[英]Exception: Neither BindingResult nor plain target object for bean name
The below register.jsp is my user registration page and want to store user details to db using hibernate but when register.jsp file runs its keep showing an exception. 下面的register.jsp是我的用户注册页面,想要使用hibernate将用户详细信息存储到db,但是当register.jsp文件运行时,其保持显示异常。 and I have mapped the form action in controller. 我已经在控制器中映射了表单动作。
register.jsp file is: In this file user details and I given action "reg" which is mapped in EmployeeController. register.jsp文件是:在此文件中,用户详细信息和给定的操作“ reg”映射到EmployeeController中。
Register.jsp Register.jsp
<form:form method="POST" action="reg.html">
<table border="0">
<tr>
<td colspan="2" align="center"><h2>Spring MVC Form Demo - Registration</h2></td>
</tr>
<tr>
<td>User Name:</td>
<td><form:input path="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><form:password path="password" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><form:input path="email" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Register" /></td>
</tr>
</table>
</form:form>
EmployeeController.java EmployeeController.java
@Controller
public class EmployeeController {
@Autowired
private UserService userService;
@RequestMapping(value = "/reg", method = RequestMethod.POST)
public ModelAndView saveUser(@ModelAttribute("command") UserBean userBean,
BindingResult result) {
User user = prepareModelUser(userBean);
userService.addUser(user);
return new ModelAndView("RegistrationSuccess.html");
}
}
From register.jsp I am trying to call saveUser method which is in EmployeeController.java but whenever I am running register.jsp I am getting an exception 我试图从register.jsp调用EmployeeController.java中的saveUser方法,但是每当我运行register.jsp时,我都会遇到异常
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute.
I tried with commandName and action in the form and in the controller I have mapped based on that. 我尝试了commandName和action的形式,并在基于此的控制器中进行了映射。 even though, it gives same exception like above. 即使,它给出了与上面相同的例外。 so how I want to configure the controller to submit this register.jsp form. 所以我要如何配置控制器以提交此register.jsp表单。 is I required to add configure the controller explicit or what.. And in EmployeeController.java I have an another form controller with same default "command" form submit. 我是否需要添加配置控制器的显式或什么。。在EmployeeController.java中,我还有另一个具有相同默认“命令”表单提交的表单控制器。 that works fine. 效果很好。 but here in this I have the possibilities what I searched. 但是在这里,我有寻找的可能性。 but does not works. 但不起作用。
you are missing commandName in the form tag and also you are doing wrong in your server side method do it like the following 您在form标记中缺少commandName,并且在服务器端方法中做错了,如下所示
In form 通知
<form:form method="POST" action="reg.html" commandName="userBean" modelAttribute="userBean" >
and in server side have it like 在服务器端有
public ModelAndView saveUser(@ModelAttribute("userBean") UserBean userBean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.