title: Spring mvc throwing exception- IllegalStateException: Neither BindingResult nor plain target object for bean , when using form tld in jsp page
body: <p>When i use plain html in jsp page , then app works fine , as i add form tag in jsp , it gives the exception , i have pasted my code and exception here , please help me out .i am not able able to resolve this and stuck from 3 days now. Whats going wrong here</p>
  
  <blockquote>
    <p>my dispatcher-servlet :</p>
  </blockquote>
  
  <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.xsd
              http://www.springframework.org/schema/mvc 
              http://www.springframework.org/schema/mvc/spring-mvc.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
          &lt;mvc:annotation-driven /&gt;
          &lt;context:component-scan
              base-package="com.shweta.*" /&gt;
          &lt;mvc:default-servlet-handler /&gt;
  
       &lt;mvc:view-controller path="/" view-name="index"/&gt;
  
          &lt;bean id="viewResolver"
                    class="org.springframework.web.servlet.view.InternalResourceViewResolver" &gt;
                    &lt;property name="prefix"&gt;
                        &lt;value&gt;/WEB-INF/jspPages/&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;/beans&gt;
  </code></pre>
  
  <blockquote>
    <p>my web.xml:   </p>
  </blockquote>
  
  <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_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;SpringMVCForm&lt;/display-name&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;1&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>
  
  <blockquote>
    <p>my Controller class:</p>
  </blockquote>
  
  <pre><code> package com.shweta.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ControllerAdvice;
  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.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.shweta.model.Employee;
  import com.shweta.model.Test;
  
  @Controller
  //@ControllerAdvice
  @RequestMapping("/employee")
  public class EmployeeController {
  
  @RequestMapping(value="/submitForm", method=RequestMethod.POST)
  public String formSubmission(@ModelAttribute("employee") Employee employee,BindingResult bindingResult)
          {
              System.out.println("entered in @RequestMapping");
              System.out.println("printing employee from modelattribute");
              System.out.println(employee.getEmail());
              System.out.println(employee.getFirstName());
              System.out.println(employee.getLastName());
              System.out.println(employee.getSalary());
              //modelMap.addAttribute("employee", employee);
              return "EmployeeWelcome";
  
          }
  
  }
  </code></pre>
  
  <blockquote>
    <p>my employee jsp page :</p>
  </blockquote>
  
  <pre><code> &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt; 
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Employee page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;${msg}&lt;/h1&gt;
  &lt;%-- &lt;form:form action="employee/submitForm" method="post" &gt; --%&gt;
  
  &lt;form:form action="${pageContext.request.contextPath}/employee/submitForm" method="post" modelAttribute="employee"&gt;
    &lt;!-- &lt;div&gt;
      First name:
      &lt;input type="text" name="firstName"&gt;
    &lt;/div&gt; --&gt;
    &lt;div&gt;
      First name:
      &lt;form:input path="firstName"/&gt;
    &lt;/div&gt;
    &lt;div&gt;
      Last name:
      &lt;input type="text" name="lastName"&gt;
    &lt;/div&gt;
    &lt;div&gt;
      E-mail:
      &lt;input type="email" name="email"&gt;
    &lt;/div&gt;
    &lt;div&gt;
     Salary:
      &lt;input type="text" name="salary"&gt;
    &lt;/div&gt;
    &lt;div class="button"&gt;
    &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/div&gt;
  &lt;/form:form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <blockquote>
    <p>my employee model class</p>
  </blockquote>
  
  <pre><code>package com.shweta.model;
  
  public class Employee {
  
      String email;
      String firstName;
      String lastName;
      Address address;
      long salary;
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public Address getAddress() {
          return address;
      }
  
      public void setAddress(Address address) {
          this.address = address;
      }
  
      public long getSalary() {
          return salary;
      }
  
      public void setSalary(long salary) {
          this.salary = salary;
      }
  
  }
  
  
  HTTP Status 500 – Internal Server Error
  Type Exception Report
  
  Message An exception occurred processing JSP page /WEB-INF/jspPages/EmployeeForm.jsp at line 22
  
  Description The server encountered an unexpected condition that prevented it from fulfilling the request.
  
  Exception
  
  org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jspPages/EmployeeForm.jsp at line 22
  
  19:   &lt;/div&gt; --&gt;
  20:   &lt;div&gt;
  21:     First name:
  22:     &lt;form:input path="firstName"/&gt;
  23:   &lt;/div&gt;
  24:   &lt;div&gt;
  25:     Last name:
  </code></pre>
  
  <blockquote>
    <p>Exception snippet</p>
  </blockquote>
  
  <pre><code>Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:613)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:505)
      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:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
      org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'employee' available as request attribute
      org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:153)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:177)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:163)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:148)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
      org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:121)
      org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:459)
      org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:356)
      org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:86)
      org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:83)
      org.apache.jsp.WEB_002dINF.jspPages.EmployeeForm_jsp._jspx_meth_form_005finput_005f0(EmployeeForm_jsp.java:214)
      org.apache.jsp.WEB_002dINF.jspPages.EmployeeForm_jsp._jspx_meth_form_005fform_005f0(EmployeeForm_jsp.java:158)
      org.apache.jsp.WEB_002dINF.jspPages.EmployeeForm_jsp._jspService(EmployeeForm_jsp.java:104)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:472)
      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:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
      org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Note The full stack trace of the root cause is available in the server logs.
  
  Apache Tomcat/7.0.94
  </code></pre>