我正在自学 Spring Form 标签,并且遇到了可能是我无法解决的简单错误。在浏览器中启动此应用程序时出现以下错误:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'index' available as request attribute
我已经尝试了 Google 搜索中出现的大多数修复程序,但均无济于事。有人能发现我哪里出错了吗?以下是相关组件。非常感谢。
控制器:
@Controller
@RequestMapping("/registration")
public class LoginController {
@RequestMapping(method = RequestMethod.GET)
public String setupForm(ModelMap model) {
Registration registration = new Registration();
model.addAttribute("registration", registration);
return "index";
}
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("registration") Registration registration, Map model) {
return "success";
}
}
JSP (/index.jsp):
<form:form commandName="index">
<table border="0" cellspacing="12">
<tr>
<td>
<form:input path="email"/>
</td>
</tr>
<tr>
<td>
<form:password path="password"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form:form>
命令对象(Registration.java):
public class Registration {
private String password;
private String email;
// getters,setters