Keep getting: Neither BindingResult nor plain target object for bean name 'index' available as request attribute

淺唱寂寞╮ 提交于 2019-12-06 15:22:52

I would make the following changes. First your GET method should be something like:

@RequestMapping(method = RequestMethod.GET)
public String showForm(@ModelAttribute("index") LoginForm loginForm) {
    return "index";
}

Using the @ModelAttribute annotation will automatically put "index" into the model for the request.

And your POST method declaration should be something like:

@RequestMapping(method = RequestMethod.POST)
public String processForm(@ModelAttribute("index") LoginForm loginForm, 
                          BindingResult result, Map model) {

Finally, and probably the real issue, change the controller class's @RequestMapping annotation to:

@RequestMapping(value = "/index")

The ".htm" that you have is redundant. You've already configured web.xml and your Spring config to respond to ".htm" requests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!