简体   繁体   English

异常:Bean名称既不是BindingResult也不是普通目标对象

[英]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.

相关问题 Springframework:BeanResult既不是BindingResult也不是普通目标对象 - Springframework : Neither BindingResult nor plain target object for bean name Spring MVC既不是BindingResult,也不是bean名称的普通目标对象 - Spring MVC Neither BindingResult nor plain target object for bean name bean 名称的 Thymeleaf 既不是 BindingResult 也不是普通目标 object - Thymeleaf Neither BindingResult nor plain target object for bean name BeanResult&#39;parametre&#39;的BindingResult和普通目标对象都不 - Neither BindingResult nor plain target object for bean name 'parametre' Bean名称为spring mvc的BindingResult或普通目标对象都没有 - Neither BindingResult nor plain target object for bean name spring mvc Bean 的 BindingResult 和普通目标 object 都不是 - Neither BindingResult nor plain target object for bean Spring MVC产生“ Bean名称&#39;command&#39;的BindingResult和普通目标对象异常都不能用作请求属性” - Spring MVC produces “Neither BindingResult nor plain target object exception for bean name 'command' available as request attribute” BeanResult&#39;configId&#39;的BindingResult或普通目标对象都不能用作请求属性Jasper Exception - Neither BindingResult nor plain target object for bean name 'configId' available as request attribute Jasper Exception BindingResult和普通目标对象都没有...异常 - Neither BindingResult nor plain target object … Exception 循环时获取“既没有 BindingResult 也没有可用作请求属性的 bean 名称‘bean 名称’的普通目标对象” - Getting "Neither BindingResult nor plain target object for bean name 'bean name' available as request attribute" when looping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM