request method 'post' not supported问题解决
来源:互联网 发布:vb浪漫小程序 编辑:程序博客网 时间:2024/05/29 09:58
最近做j2ee开发时,使用spring框架,用jquery的ajax方法提交表单时,遇到了request method ‘post’ not supported这个警告而且数据传送不成功,于是在百度上搜了一下,可能是表单提交时没有填写数据导致的以及其他可能的原因,我调试了一天,还是未解决这个问题。于是问了项目经理,他一看我的代码就说这个是url的问题吧,我看了一下原来url写了相对路径,这个就无法提交,于是获取前面加了base标签:数据发送成功,在此记录一下以免以后再犯。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><base href="<%=basePath%>"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script src="js/jquery-3.2.1.js"></script><!-- 新 Bootstrap4 核心 CSS 文件 --><link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"><!-- jQuery文件。务必在bootstrap.min.js 之前引入 --><script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script><!-- popper.min.js 用于弹窗、提示、下拉菜单 --><script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script><!-- 最新的 Bootstrap4 核心 JavaScript 文件 --><script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script></head><body> <div align="center"> <form action="login" onsubmit="return false;" id="userForm" method="post"> <table class="table table-hover"> <thead> <tr> <input type="text" name="name" placeholder="登录账号" /> </tr> </thead> <tbody> <tr> <input type="password" name="pwd" placeholder="登录密码" /> </tr> <tr> <button type="button" class="btn" onclick="userLogin()">基本按钮</button> </tr> </tbody> </table> <br> </form> </div> <script type="text/javascript"> function userLogin() { $.ajax({ type : "post", url : "login", data : $("#userForm").serialize(), dataType : "json", success : function(data) { alert(data.flag); if (data.flag == "ok") { location.href = "index"; } else { alert("登录失败!"); } } }) } </script></body></html>
主要是没有加
<% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%>
和
<base href="<%=basePath%>">
加上以后,问题解决。记得base标签放head第一行
这个世界上没有知识是学不会的,不是吗?如果一开始学不会,就可以把问题细化分解,然后学习更基本的知识。最后,所有问题都能变得和1+1=2一样简单,我们需要的只是时间。好了,最后给大家推荐一个学习Java的好网站JAVA自学网站–how2j.cn
阅读全文
0 0
- request method 'post' not supported问题解决
- request method 'post' not supported
- Request method 'POST' not supported
- Spring MVC-Request method 'POST' not supported:
- springmvc解决 405 request method post not supported(Request method 'POST' not supported)
- curl发送post请求出现:Request method 'post' not supported
- 关于HTTP Status 500 - Request method 'POST' not supported分析
- HTTP Status 405 - Request method 'POST' not supported (Spring MVC)
- Spring MVC Request method 'POST' not supported错误
- Request method 'GET' not supported
- Request method 'GET' not supported
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
- SpringBoot 调用ajax POST 方法报Request method 'POST' not supported解决方法
- 在pring框架出现 405 request method post not supported 的解决方法
- Spring MVC HTTP Status 405 – Request method ‘POST’ not supported
- 使用springmvc提交put请求时提示 Request method 'POST' not supported
- spring MVC form表单提交用RequestMethod.POST报错 : Request method 'GET' not supported
- spring mvc处理json文件静态资源文件报错Request method 'POST' not supported
- Caffe2的安装详述
- dobbo核心代码
- VLC Web Plugin 如何在ubantu linux系统上安装使用
- 【新手教程】win2008 ftp图文教程,从此ftp再也不是个问题啦
- oracle-ORA-12012: error on auto execute of job "SYS"."ORA$AT_SA_SPC_SY_%
- request method 'post' not supported问题解决
- 如何正确地写出单例模式
- Gitlaba安装配置
- 小白入坑c++之路启程篇
- SQL Server 语法大全
- OBIEE12C导出到excel 修改最大单元格数
- tp5学习 生成目录
- DBMS_LOB的简单用法以及释放DBMS_LOB生成的临时CLOB内存
- Celery-4.1 用户指南: Debugging