报错:
org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
警告: Request method 'POST' not supported
环境:
使用SpringMVC实现登录控制,UserController类里有两个方法,分别是
@RequestMapping(value = "/login",method = RequestMethod.GET)
public String login(){
return "/login";
}
@RequestMapping(value = "/sublogin",method = RequestMethod.POST)
public String login(String username, Model model){
if(username.equals("nuan")) {
model.addAttribute("username",username);
return "/admin";
}
model.addAttribute("loginResult","fail");
return "forward:/user/login";
}
原因:return "forward:/user/login";验证失败,应该重新定向到登录界面,即return "redirect:/user/login";
另外,对于登录方法,一般都会写做/login,只是一个GET方法,一个POST方法
@RequestMapping(value = "/login",method = RequestMethod.GET) public String login(){ return "/login"; } @RequestMapping(value = "/login",method = RequestMethod.POST) public String login(String username, Model model){ if(username.equals("nuan")) { model.addAttribute("username",username); return "/admin"; } model.addAttribute("loginResult","fail"); return "forward:/user/login"; }
不修改请求转发的错误,会报另外一个错误
Handler processing failed; nested exception is java.lang.StackOverflowError
大概是验证失败会不断地请求转发到POST方法,积累到一定量,就会崩溃。