title: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
body: <p>I looked almost all answers related this problem on the web but could not figure out the problem in my code. </p>
  
  <p>Here is my JSP page.</p>
  
  <pre><code>&lt;form:form method="POST" commandName="category" modelAttribute="category" action="search_category"&gt;
      &lt;form:input path="category_name" /&gt; 
      &lt;input type="submit" value="Submit"&gt;  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>When I delete </p>
  
  <pre><code>&lt;form:input path="category_name" /&gt; 
  </code></pre>
  
  <p>It works fine. I can communicate with my controller. So the problem is related to this line.</p>
  
  <pre><code>@Controller
  public class SearchCategory {
  
      @Autowired      
      private CategoryService categoryService;
  
      @RequestMapping(value = "/search_category",  method = RequestMethod.POST)
      public @ResponseBody String searchCategoryFromDatabase(@ModelAttribute("category") Category category, BindingResult result){        
  
          return "something";
      }
  }
  </code></pre>
  
  <p>Here is my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
       &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;  
      &lt;context-param&gt;  
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;  
          &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;  
      &lt;/context-param&gt;  
  
      &lt;filter&gt;  
          &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt;  
          &lt;filter-class&gt;org.springframework.orm.hibernate4.support.OpenSessionInViewFilter&lt;/filter-class&gt;  
      &lt;/filter&gt;  
      &lt;filter-mapping&gt;  
          &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt;  
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;  
      &lt;/filter-mapping&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>This is my servlet-context.xml </p>
  
  <pre><code>&lt;!--  Set the default page as index.jsp --&gt;
  &lt;mvc:view-controller path="/" view-name="index"/&gt;
  
  &lt;!-- Map resources --&gt; 
  &lt;mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" /&gt; 
  
  &lt;!-- Map simple view name such as "test" into /WEB-INF/views/test.jsp --&gt;
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>And my applicationContext.xml</p>
  
  <pre><code>&lt;!-- Enable @Controller annotation support --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;context:annotation-config/&gt;    
  
      &lt;!--  Set the default page as index.jsp --&gt;
      &lt;mvc:view-controller path="/" view-name="index"/&gt;
  
       &lt;!-- Map resources --&gt; 
      &lt;mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" /&gt; 
  
      &lt;!-- Map simple view name such as "test" into /WEB-INF/views/test.jsp --&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Scan classpath for annotations (eg: @Service, @Repository etc) --&gt;
      &lt;context:component-scan base-package="com.XXXX"/&gt;
  
      &lt;!-- JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with 
           username root and blank password. Change below if it's not the case --&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/XXXX"/&gt;
          &lt;property name="username" value="XXXX"/&gt;
          &lt;property name="password" value="XXXX"/&gt;
          &lt;property name="validationQuery" value="SELECT 1"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Hibernate Session Factory --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="packagesToScan"&gt;
              &lt;array&gt;
                  &lt;value&gt;com.XXXX&lt;/value&gt;
              &lt;/array&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;value&gt;
                  hibernate.dialect=org.hibernate.dialect.MySQLDialect
              &lt;/value&gt;
          &lt;/property&gt;     
      &lt;/bean&gt;
  
      &lt;!-- Hibernate Transaction Manager --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Activates annotation based transaction management --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;  
  </code></pre>
  
  <p>I am probably doing something wrong in my XML files. I am new for this Spring - Hibernate staff so waiting for your help. Thanks..</p>
  
  <p>This is the exception getting thrown</p>
  
  <pre><code>Stacktrace:] with root cause
  java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
      at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:141)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
      at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
      at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
      at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
      at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
      at org.apache.jsp.index_jsp._jspx_meth_form_005finput_005f0(index_jsp.java:208)
      at org.apache.jsp.index_jsp._jspx_meth_form_005fform_005f0(index_jsp.java:168)
      at org.apache.jsp.index_jsp._jspService(index_jsp.java:100)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:149)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>