开发者

Spring MVC 3: java.lang.IllegalStateException

开发者 https://www.devze.com 2023-03-06 22:12 出处:网络
Hi Could someone help me understand what am I doing wrong in the following code due to which I am getting this error:

Hi Could someone help me understand what am I doing wrong in the following code due to which I am getting this error:

Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementT开发者_JAVA技巧ag.java:160)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122)
    at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
    at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
    at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
    at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspx_meth_form_005finput_005f0(signUp_jsp.java:179)
    at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspx_meth_form_005fform_005f0(signUp_jsp.java:111)
    at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspService(signUp_jsp.java:74)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    ... 59 more

UserManagementController.java

@Controller
public class UserManagementController { 
    //displays sign up page(GET)
    @RequestMapping(method=RequestMethod.GET, value="/signUp.html")
    public ModelAndView signUpForm() {
        System.out.println("Sign up");
        return new ModelAndView("/signUp", "user", new User());
    }

}

signUp.jsp

<body>
    <h3>Sign up</h3>
    <table>
        <form:form commandName="user" >
            <tr>
                <td>First name:</td>
                <td><form:input path="firstName"/></td>
            </tr>
            <tr>
                <td>Last name:</td>
                <td><form:input path="lastName"/></td>
            </tr>
            <tr>
                <td>Username:</td>
                <td><form:input path="username"/></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><form:input path="password"/></td>
            </tr>
            <tr>
                <td>Email:</td>
                <td><form:input path="email"/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Submit"></td>
            </tr>
        </form:form>
    </table>
</body>

Could someone help me understand it?

Thanks.


I was mistakenly using the wrong import for ModelAndView. I was supposed to use org.springframework.web.servlet.ModelAndView but the one I was mistakenly using was org.springframework.web.portlet.ModelAndView.

I've got the code working now.

Thanks :)

0

精彩评论

暂无评论...
验证码 换一张
取 消