title: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
body: <p>I am beginner to Spring MVC Framework. I started to learn Spring two days back. For learning purpose I am developing one simple Application. i.e., Get user input from form and display values in another page. I got an Exception " java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute". I cant figure out what's wrong in my code. I searched Google and tried many solution but the problem is still here.</p>
  
  <p>Here is my view
  index.jsp</p>
  
  <pre><code>&lt;form:form action="/addDisplay" method="POST"&gt;
       &lt;form:label path="name"&gt;&lt;h3&gt;Name&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="text" path="name" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="age"&gt;&lt;h3&gt;Age&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="number" path="age" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="work"&gt;&lt;h3&gt;Work Place&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="text" path="work" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="designation"&gt;&lt;h3&gt;Designation&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="text" path="designation" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="area"&gt;&lt;h3&gt;Area&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="text" path="area" placeholder="Where Are You From?" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="mobile"&gt;&lt;h3&gt;Mobile Number&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="number" path="mobile" placeholder="Your Mobile Number.!" cssClass="form-control text-center" required="required"/&gt;
  
       &lt;form:label path="email"&gt;&lt;h3&gt;Email&lt;/h3&gt;&lt;/form:label&gt;
       &lt;form:input type="email" path="email" placeholder="Your Email Id..!" cssClass="form-control text-center" required="required"/&gt;
       &lt;br/&gt;
       &lt;input type="submit" value="Generate" class="btn btn-success form-control"/&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>myself.jsp</p>
  
  <pre><code>&lt;div style="margin-top: 3%; font-size: 20px;"&gt;
      &lt;h3&gt;My Introduction.&lt;/h3&gt;
         &lt;p&gt;
          Hi, I am ${name} my age is ${age} and I am from ${area}. I am working as a ${designation}  
          in ${work}. You can contact me in my mobile ${mobile} and You can also shoot mail to 
          ${email}.
         &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;SpringWork&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/mvc-dispatcher-servlet.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>mvc-dispatcher-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans     
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
          &lt;context:component-scan base-package="com.infofaces.spring.form" /&gt;
          &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
              &lt;property name="prefix"&gt;
                  &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
              &lt;/property&gt;
              &lt;property name="suffix"&gt;
                  &lt;value&gt;.jsp&lt;/value&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
              &lt;property name="basename" value="com/infofaces/spring/form/MySelf" /&gt;
          &lt;/bean&gt;
  
          &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
          &lt;mvc:annotation-driven /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My model name is Myself.java and it has private variables and getter, setter methods for that variable. Here is my controller.</p>
  
  <p>HelloController.java</p>
  
  <pre><code>package com.infofaces.spring.form;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  public class HelloController {
  
      @RequestMapping(value = "/display", method = RequestMethod.GET)
      public ModelAndView display() {
          return new ModelAndView("myself", "command", new MySelf());
      }
  
      @RequestMapping(value="/addDisplay", method = RequestMethod.POST)
      public String addDisplay(@ModelAttribute("command") MySelf myself, ModelMap model) {
          model.addAttribute("name",myself.getName());
          model.addAttribute("age", myself.getAge());
          model.addAttribute("work", myself.getWork());
          model.addAttribute("designation", myself.getDesignation());
          model.addAttribute("mobile", myself.getMobile());
          model.addAttribute("email", myself.getEmail());
          return "myself";
      }
  }
  </code></pre>
  
  <p>Full Stack Trace.</p>
  
  <pre><code>type Exception report
  
  message java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
      org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:141)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
      org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:130)
      org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:120)
      org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:90)
      org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
      org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
      org.apache.jsp.index_jsp._jspx_meth_form_005flabel_005f0(index_jsp.java:265)
      org.apache.jsp.index_jsp._jspx_meth_form_005fform_005f0(index_jsp.java:170)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:105)
      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:395)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>Please help to find problem in my code. Thanks in advance.</p>