title: "org.apache.jasper.JasperException" after failing form validation
body: <p>I always get the following error when my form fails to validate:</p>
  
  <blockquote>
    <p>org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'regform' available as request attribute</p>
  </blockquote>
  
  <p>I don't get this error when the form input is valid. The root cause is</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException:
    Neither BindingResult nor plain target
    object for bean name 'regform'
    available as request attribute</p>
  </blockquote>
  
  <p>Here is <code>net.sandbox.controllers.RegistrationController</code> with the imports omitted for brevity's sake:</p>
  
  <pre><code>@Controller
  @RequestMapping("/register")
  public class RegistrationController {
      @Autowired
      private UserInfo userInfo;
  
      @RequestMapping(method = RequestMethod.GET)
      public String showRegForm(Model model) {
          RegistrationForm regForm = new RegistrationForm();
          model.addAttribute("regform", regForm);
          return "regform";
      }
  
      @RequestMapping(method = RequestMethod.POST)
      public String validateForm(@Valid RegistrationForm regForm, BindingResult result, Model model) {
          if (result.hasErrors()) {
              return "regform";
          }
  
          userInfo.setUserName(regForm.getFirstName());
          model.addAttribute("regform", regForm);
          return "regsuccess";
      }
  }
  </code></pre>
  
  <p>What does it mean?</p>
  
  <hr>
  
  <p><strong>Update</strong>: added requested JSP files.</p>
  
  <p><code>regform.jsp</code></p>
  
  <pre><code>&lt;jsp:include page="includes/header.jsp"&gt;
      &lt;jsp:param name="pageTitle" value="Registration" /&gt;
  &lt;/jsp:include&gt;
  &lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
          &lt;h2&gt;Register below.&lt;/h2&gt;
          &lt;form:form method="post" commandName="regform"&gt;
              &lt;p&gt;&lt;form:input path="firstName" /&gt; &lt;form:errors path="firstName" /&gt;&lt;/p&gt;
              &lt;p&gt;&lt;input type="submit" /&gt;&lt;/p&gt;
          &lt;/form:form&gt;
  &lt;jsp:include page="includes/footer.jsp" /&gt;
  </code></pre>
  
  <p><code>header.jsp</code></p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;jsp:useBean id="userInfo" scope="session" class="net.sandbox.sessionbeans.UserInfo" /&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;&lt;%= request.getParameter("pageTitle") %&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1 style="float: left; width: 50%"&gt;Sandbox -- &lt;%= request.getParameter("pageTitle") %&gt;&lt;/h1&gt;
          &lt;h4 style="float: left; text-align: right; width: 50%"&gt;&lt;% out.print(userInfo.getUserName()); %&gt;&lt;/h4&gt;
          &lt;hr style="clear: both" /&gt;
  </code></pre>
  
  <p><code>footer.jsp</code></p>
  
  <pre><code>    &lt;hr /&gt;
      &lt;p&gt;&lt;i&gt;Copyright information goes here.&lt;/i&gt;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>