title: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
body: <p>I started learning Spring these days,Iam getting below exception: Iam just tring to navigate from login page (will do insert opeartion in db later using DAOs) to some index.jsp page</p>
  
  <pre><code>exception
  
  org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 11
  
  8: &lt;/head&gt;
  9: &lt;body&gt;
  10: &lt;form:form method="post" commandName="user" action="login"&gt;
  11:     &lt;form:label path="uname" /&gt; &lt;form:input path="uname" /&gt;
  12:     &lt;form:label path="password" /&gt;  &lt;form:input path="password" /&gt;
  13:     &lt;input type="submit" value="Submit" /&gt;
  14: &lt;/form:form&gt;
  
  
  Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:424)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  root cause
  
  java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' 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.login_jsp._jspx_meth_form_005flabel_005f0(login_jsp.java:157)
      org.apache.jsp.login_jsp._jspx_meth_form_005fform_005f0(login_jsp.java:111)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:71)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </code></pre>
  
  <p><strong>login.jsp</strong></p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;&lt;%@ taglib
      prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  &lt;!DOCTsYPE html&gt;
  &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;form:form method="post" commandName="user" action="login"&gt;
      &lt;form:label path="uname" /&gt; &lt;form:input path="uname" /&gt;
      &lt;form:label path="password" /&gt;  &lt;form:input path="password" /&gt;
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>LoginController.java</strong></p>
  
  <pre><code>package com.bts.controller;
  
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.SessionAttributes;
  
  @Controller
  @RequestMapping("/login")
  @SessionAttributes("user")
  public class LoginController {
  
      @RequestMapping(method=RequestMethod.POST)
      public String  onSubmit(){
          System.out.println("entered in submit methodd....");
          return "index";
      }
  }
  </code></pre>
  
  <p><strong>web.xml</strong></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;BugTrackingSystem&lt;/display-name&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/application-context.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;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>User.java</strong>
  *<em>strong text</em>*</p>
  
  <pre><code>package com.bts.vo;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class User {
  
      public User() {
  
          countries = new ArrayList&lt;String&gt;();
  
          countries.add("India");
          countries.add("US");
  
      }
  
      private String uname;
      private String password;
      private List&lt;String&gt; countries;
  
      public String getUname() {
          return uname;
      }
      public void setUname(String uname) {
          this.uname = uname;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      public List&lt;String&gt; getCountries() {
          return countries;
      }
      public void setCountries(List&lt;String&gt; countries) {
          this.countries = countries;
      }
  
  }
  </code></pre>
  
  <p><strong>application-context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      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"&gt;
  
    &lt;import resource="dispatcher-servlet.xml"/&gt;
    &lt;import resource="datasource.xml"/&gt;
    &lt;import resource="hibernate-beans.xml"/&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      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"&gt;
  
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/jsp/&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;context:component-scan base-package="com.bts.controller" /&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Please someone can run my code and provide me solution.. :)</strong></p>