Neither BindingResult nor plain target object for bean name available

Neither BindingResult nor plain target object for bean name available

If you see below exception while working on Spring MVC:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'person' available as request attribute
    org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
    org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
    org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    org.apache.jsp.WEB_002dINF.jsp.helloWorld_jsp._jspx_meth_form_005finput_005f0(helloWorld_jsp.java:185)
    org.apache.jsp.WEB_002dINF.jsp.helloWorld_jsp._jspx_meth_form_005fform_005f0(helloWorld_jsp.java:148)
    org.apache.jsp.WEB_002dINF.jsp.helloWorld_jsp._jspService(helloWorld_jsp.java:106)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Answer: It means on jsp page you are using binding object but not returning it from controller.

  • For example: On JSP page if your form is below:
<form:form commandName="person" method="post" action="helloWorld.web">
  • then below mapping on controller will throw exception:
@RequestMapping(value="/helloWorld.web",method = RequestMethod.POST)
    public String printWelcome(ModelMap model) {

        model.addAttribute("message", "Hello World!!!");
        return "helloWorld";

    }
  • To fix this add object as below:
@RequestMapping(value = "/helloWorld.web", method = RequestMethod.GET)
    public String printWelcome(@ModelAttribute("person") Person person,
            ModelMap model) {

        model.addAttribute("message", "Hello World!!!");
        return "helloWorld";

    }

Leave a Reply

Your email address will not be published. Required fields are marked *