我收到以下警告: 不支持請求方法'POST'。不支持Spring MVC-Request方法'POST':org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
控制器方法:
@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";
}
}
分配器一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和相應地在登錄頁面,然後它會工作。
請注意,問題是在返回「static/profile.html」;
FYI profile.html的位置是WEB-INF /靜態/
謝謝!
獲取的警告在哪裏呢?你是否將'login'中的登錄信息作爲請求參數提交或作爲表單提交? – chrylis
你確定你的表單的URL是否正確,action屬性是action =「POST」? – isah
請發佈http表單,發送的請求以及控制器類的類關鍵字旁邊的註釋。 – Ralph