title: SimpleFormController - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command'
body: <p>In my basic spring mvc application I am getting the exception. I am using <code>SimpleFormController</code>. My code is as below.</p>
  
  <p>In my dispatcher-servlet </p>
  
  <pre><code>&lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
      &lt;property name="mappings"&gt;
          &lt;props&gt;
              &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt;
             &lt;!-- &lt;prop key="login.htm"&gt;loginController&lt;/prop&gt;  --&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/"
        p:suffix=".jsp" /&gt;
  
  &lt;!--
  The index controller.
  --&gt;
  &lt;bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" /&gt;
  &lt;!--  &lt;bean name="loginController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="login"/&gt;  --&gt;
  
   &lt;bean name="/login.htm" class="com.pack.controller.LoginController" &gt;
   &lt;property name="commandClass" value="com.pack.model.User" /&gt;
   &lt;property name="formView" value="login"/&gt;
   &lt;property name="successView" value="index.htm"/&gt;
   &lt;/bean&gt;
  </code></pre>
  
  <p>In my JSP page</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Login&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Login&lt;/h1&gt;
          &lt;form:form name="loginForm" method="post"&gt;
          ${msg}
          &lt;form:input id="username" path="username"/&gt;
          &lt;form:password id="password" path="password"/&gt;
          &lt;input type="submit" value="login" name="login" /&gt;
          &lt;/form:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In my controller class</p>
  
  <pre><code>public class LoginController extends SimpleFormController{
  
      @Override
      public ModelAndView onSubmit(Object command) throws ServletException {
          User user =  (User)command;
          System.out.println("Username:" + user.getUsername() + " Password:" + user.getPassword());
          if(user.getUsername().equalsIgnoreCase("sa") &amp;&amp; user.getPassword().equalsIgnoreCase("12")){
              return new ModelAndView(new RedirectView(getSuccessView()));
          }
          else
          {
              ModelAndView modelAndView = new ModelAndView("login");
              modelAndView.addObject("msg", "Invalid login");
              return  modelAndView;
          }
      }    
  }
  </code></pre>
  
  <p>Once the user enter correct username and password will redirect to the <code>index</code> page. This is working properly. But the user enter wrong login credentials it throws this error.</p>
  
  <blockquote>
    <p>exception<br>
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute<br>
    root cause<br>
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute</p>
  </blockquote>
  
  <p>Any suggestion to solve this issue?</p>