浏览器响应如下:
服务器拒绝此请求,因为请求实体的格式不受所请求的方法的资源的支持。
而不是重定向到主页( home.jsp )
welcome.jsp文件:
<form method ="POST" action = "<c:url value='/login'/>" >
<input id="name" name="name" type="text">
<input id="password" name="password" type="password">
<input type="submit" id="loginNew" value="LoginNew">
</form>控制器类:
@RequestMapping( value="/login" , method = RequestMethod.POST )
public ModelAndView authenticate ( @RequestBody User userObj ) throws Exception {
ModelAndView modelAndView = new ModelAndView ();
try {
user = userService.authenticateUser ( userObj );
} catch ( Exception e ) {
e.printStackTrace();
}
modelAndView.setViewName("/home");
return modelAndView;
}发布于 2017-04-30 12:23:55
通过在方法中添加@ModelAttribute而不是@RequestBody,param解决了这个问题,然后按预期重定向到home.jsp页面。
@RequestMapping( value="/login" , method = RequestMethod.POST )
public ModelAndView authenticate ( @ModelAttribute User userObj ) throws Exception {
ModelAndView modelAndView = new ModelAndView ();
try {
user = userService.authenticateUser ( userObj );
} catch ( Exception e ) {
e.printStackTrace();
}
modelAndView.setViewName("/home");
return modelAndView;
}https://stackoverflow.com/questions/43706311
复制相似问题