title: Neither BindingResult nor plain target object ... Exception
body: <p>Yes, I read it is pretty common problem, but reading those post did not really help me.</p>
  
  <p>The <strong>short story</strong> is that I wanna submit a form on showAllComments.jsp</p>
  
  <pre><code>&lt;form:form method="post" action="postNewComment.html"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="comment"&gt;
                          COMMENT
                      &lt;/form:label&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="comment" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2"&gt;&lt;input type="submit"
                      value="WRITE" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  </code></pre>
  
  <p>Here is the controller:</p>
  
  <pre><code>@Controller
  @SessionAttributes
  public class CommentController {
  
  
      @Autowired
      private CommentService commentService;
  
  
      @RequestMapping(value = "/postNewComment", method = RequestMethod.POST)
      public ModelAndView showAllUsers(@ModelAttribute("command") Comment comment, BindingResult result) {
  
  
          System.out.println(comment.getComment());
  
          Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
          model.put("COMMENTS", commentService.getComments());
  
          return new ModelAndView("showAllComments", model);
      }
  }
  </code></pre>
  
  <p>and here is the result:
  <strong>java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute</strong></p>
  
  <p>But probably you need to see the <strong>whole story</strong>, from the beginning:
  The user starts the application on index.jsp by clicking </p>
  
  <pre><code>&lt;a href="toLoginPage.html"&gt;Log in&lt;/a&gt; 
  </code></pre>
  
  <p>That link takes him to LoginController</p>
  
  <pre><code>@RequestMapping("/toLoginPage")
      public ModelAndView goToLoginPage() {
          return new ModelAndView("login", "command", new User());
  }
  </code></pre>
  
  <p>Then he is taken to login.jsp where he provides his username and password.</p>
  
  <pre><code>&lt;form:form method="post" action="log_in.html"&gt;
  
          &lt;input type="text" name="uName" /&gt;
          &lt;input type="password" name="pW" /&gt;
  
          &lt;input type="submit" value="Log IN"&gt;
      &lt;/form:form&gt; 
  </code></pre>
  
  <p>he submits the form and he is taken back to LoginController</p>
  
  <pre><code>@RequestMapping(value = "/log_in", method = RequestMethod.POST)
      public ModelAndView tryToLogin(@RequestParam("uName") String uName, @RequestParam("pW") String pW, HttpServletResponse response, HttpServletRequest request) {
          ModelAndView ret = new ModelAndView("login", "command", new User());
          User user = userService.existingUser(uName, pW);
          loggedInUser = new User();
          if (user != null) {
              Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
                  model.put("COMMENTS", allComments);
                  model.put("LOGGED_IN_USER", loggedInUser);
              ret = ModelAndView("showAllComments", model);
          }
          return ret;
      }
  </code></pre>
  
  <p>After successful login he is on the showAllComments page where he sees all the comments and he should be able to  add his own comment but submitting the above mentioned form throws the above mentioned exception. I feel something is missing but I can't figure out what it is. Just for the record I show the 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      id="WebApp_ID" version="2.5"&gt;
      &lt;display-name&gt;Spring3MVC&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring&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;spring&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and the spring-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
      &lt;context:property-placeholder location="classpath:jdbc.properties" /&gt;
      &lt;context:component-scan base-package="net" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${database.driver}" /&gt;
          &lt;property name="url" value="${database.url}" /&gt;
          &lt;property name="username" value="${database.user}" /&gt;
          &lt;property name="password" value="${database.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;net.model.User&lt;/value&gt;
                  &lt;value&gt;net.model.Comment&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="hibernateTransactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="classpath:messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="localeChangeInterceptor"
          class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
          &lt;property name="paramName" value="lang" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="localeResolver"
          class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
          &lt;property name="defaultLocale" value="en" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="handlerMapping"
          class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"&gt;
          &lt;property name="interceptors"&gt;
              &lt;ref bean="localeChangeInterceptor" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>