Spring MVC-Request method 'POST' not supported:
来源:互联网 发布:政务数据资源管理平台 编辑:程序博客网 时间:2024/05/19 19:57
Spring MVC-Request method 'POST' not supported: org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
Spring MVC请求的方法“后”不支持:org.springframework.web.servlet.pagenotfound handlehttprequestmethodnotsupported
问题 (Question)
I am getting the following warning: Request method 'POST' not supported.
Controller method:
@Controllerpublic class UserServiceController {@RequestMapping(value = "/login", method = RequestMethod.POST)@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)public String login(@RequestParam Map<String,String> requestParams) throws Exception{ System.out.println(requestParams.values()); loginService.userAuthentication(requestParams.get("loginuname"), requestParams.get("loginpassword")); System.out.println("Before return"); return "static/profile.html";}}
Dispatcher-servlet.xml
<mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
index.html
<script language="javascript" type="text/javascript">function submitForm(){ document.login.submit();}</script><div id="login" class="login"> <form action="http://localhost:8080/SampleApp/login" name="login" method="post"> <input type="text" value = "Email" name="loginuname" id="loginuname" class="loginbasetxt"> <input type="text" value="Password" name="loginpassword" id="loginpassword" class="loginbasetxt"> <img src="static/img/tb-login-button.png" onclick="submitForm()"/></form> </div>
However, if i would change the method=RequestMethod.GET and correspondingly at login page then it would work.
Please note, problem is at return "static/profile.html";
FYI location of profile.html is WEB-INF/static/
Thanks!!
我得到以下警告:请求方法后不。
控制器的方法:
@Controllerpublic class UserServiceController {@RequestMapping(value = "/login", method = RequestMethod.POST)@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)public String login(@RequestParam Map<String,String> requestParams) throws Exception{ System.out.println(requestParams.values()); loginService.userAuthentication(requestParams.get("loginuname"), requestParams.get("loginpassword")); System.out.println("Before return"); return "static/profile.html";}}
dispatcher-servlet.xml
<mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
index.html
<script language="javascript" type="text/javascript">function submitForm(){ document.login.submit();}</script><div id="login" class="login"> <form action="http://localhost:8080/SampleApp/login" name="login" method="post"> <input type="text" value = "Email" name="loginuname" id="loginuname" class="loginbasetxt"> <input type="text" value="Password" name="loginpassword" id="loginpassword" class="loginbasetxt"> <img src="static/img/tb-login-button.png" onclick="submitForm()"/></form> </div>
然而,如果我能改变的方法requestmethod.get对应在登录页面,然后它会工作。
请注意,问题是返回“静态HTML /配置文件。”;
仅供参考位置profile.html是WEB-INF /静态/
谢谢!!
最佳答案 (Best Answer)
When you POST
a form to an HTTP server, the form's contents aren't sent as query parameters; instead, the form is (usually) uploaded as an entity of type application/x-www-form-urlencoded
. Instead of using @RequestParam
in your method, define a Java class that has fields corresponding to the form fields, and use @ModelAttribute FormClass form
.
当你POST
一个形成一个HTTP服务器,表单的内容不是作为查询参数发送;相反,形式(通常)作为实体类型上传application/x-www-form-urlencoded
。而不是使用@RequestParam
在你的方法,定义了一个Java类,对应于形成域域,并使用@ModelAttribute FormClass form
。
答案 (Answer) 2
you should try this:
return "forward:/static/profile.html";
你应该试试这个:
return "forward:/static/profile.html";
- Spring MVC-Request method 'POST' not supported:
- HTTP Status 405 - Request method 'POST' not supported (Spring MVC)
- Spring MVC Request method 'POST' not supported错误
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
- request method 'post' not supported
- Request method 'POST' not supported
- Spring MVC HTTP Status 405 – Request method ‘POST’ not supported
- spring MVC form表单提交用RequestMethod.POST报错 : Request method 'GET' not supported
- spring mvc处理json文件静态资源文件报错Request method 'POST' not supported
- request method 'post' not supported问题解决
- springmvc解决 405 request method post not supported(Request method 'POST' not supported)
- Spring mvc 405 Request method 'POST' not support
- curl发送post请求出现:Request method 'post' not supported
- jsp spring mvc 上传时HTTP Status 405 - Request method 'GET' not supported是什么原因
- 关于HTTP Status 500 - Request method 'POST' not supported分析
- Request method 'GET' not supported
- Request method 'GET' not supported
- SpringBoot 调用ajax POST 方法报Request method 'POST' not supported解决方法
- java 生成 解析XML 文件 Dom4J
- Trusting all certificates with okHttp
- PIC24F32KA304-关于UART轮训发送数据出现数据发送不全问题的解决
- maven自定义目录
- log4j配置
- Spring MVC-Request method 'POST' not supported:
- Range
- hadoop配置文件
- 梵塔问题
- Linux vi命令
- hdu3586 Information Disturbing 树形DP
- 在linux中数据库备份遇到的问题
- ceph入门----ceph安装
- pdf转换成txt文件的操作步骤解析