Spring MVC-Request method 'POST' not supported:

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:

@Controller
public 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!!

我得到以下警告:请求方法后不。

控制器的方法:

@Controller
public 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 /静态/

谢谢!!

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

最佳答案 (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";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值