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

Tags: java spring spring-mvc source
标签: java spring spring-mvc source

问题 (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 /静态/

谢谢!!

<iframe id="cproIframe_u1803835_1" width="336" height="280" src="http://pos.baidu.com/acom?adn=3&amp;at=231&amp;aurl=&amp;cad=1&amp;ccd=24&amp;cec=UTF-8&amp;cfv=16&amp;ch=0&amp;col=zh-CN&amp;conBW=0&amp;conOP=1&amp;cpa=1&amp;dai=1&amp;dis=0&amp;ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DV2xIMLWldQWJx7FyAa8ZV6MPUctyDYnX1Jc0ISDUQ0A_AiUV2_NGbl6-JUiWWAy2O2K6jnKkFOHwt7u1iqChLn3eKzZGHyafWruO3b01p7BFS8wtKC1OPT0LcuS_rQ40TXXZ5tqvPASwvH9V3HprJYqEdyBz_XSwK74GyOysa53KPfS8UeR4lvsgdQqYaF7aCBwyCc_aiJR1PG26ZgDTY8k-GMdqmxWEnjnCCF8lwN_%26wd%3D%26eqid%3Dfc8b8ff8000c8e1c0000000556272a6e&amp;ltu=http%3A%2F%2Fwww.4byte.cn%2Fquestion%2F208791%2Fspring-mvc-request-method-post-not-supported-org-springframework-web-servlet-pagenotfound-handlehttprequestmethodnotsupported.html&amp;lu_161=0&amp;lunum=6&amp;n=55082150_cpr&amp;pcs=1349x667&amp;pis=10000x10000&amp;ps=1964x509&amp;psr=1366x768&amp;pss=1349x2249&amp;qn=f974aab61a5cf7a9&amp;rad=&amp;rsi0=336&amp;rsi1=280&amp;rsi5=4&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rss7=&amp;scale=&amp;skin=tabcloud_skin_3&amp;stid=5&amp;td_id=1803835&amp;titFF=%E5%AE%8B%E4%BD%93&amp;titFS=12&amp;titTA=left&amp;tn=text_default_336_280&amp;tpr=1445407408400&amp;ts=1&amp;version=2.0&amp;xuanting=0&amp;dtm=BAIDU_DUP2_SETJSONADSLOT&amp;dc=2&amp;di=u1803835&amp;ti=Spring%20MVC-Request%20method%20%27POST%27%20not%20supported%3A%20org.springfr&amp;tt=1445407408395.5.478.480" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: border-box;"></iframe>

最佳答案 (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";
0 0
原创粉丝点击