title: Neither BindingResult nor plain target object for bean name 'userProfile' available as request attribute
body: <p>I've encountered the folowing exception while I was trying to implement my first spring+hibernate web app:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userProfile' available as request attribute
      at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:141)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
      at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
      ...
  </code></pre>
  
  <p>UserController.java:</p>
  
  <pre><code>@Controller
  public class UserController {
  
      @Autowired
      private UserProfileService userProfileService;
  
      public UserController(){
  
      }
  
      @RequestMapping(value="/add", method=RequestMethod.POST)
      public String registerUser(@ModelAttribute("userProfile") UserProfile userProfile, BindingResult result, Map model){
  
          userProfileService.addUserProfile(userProfile);
  
          return "redirect:/login";
      }
      ...
  }
  </code></pre>
  
  <p>UserProfile.java</p>
  
  <pre><code>@Entity
  @Table(name="USER_PROFILE")
  public class UserProfile {
      @Id
      @GeneratedValue
      @Column(name = "ID")
      private Long id;
  
      @Column(name = "USERNAME")
      private String userName;
  
      @Column(name = "PASSWORD")
      private String password;
  
      //sets and gets
  }
  </code></pre>
  
  <p>index.jsp</p>
  
  <pre><code>&lt;form:form method="post" action="add" commandName="userProfile"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="userName"&gt;&lt;spring:message code="label.username" /&gt;&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="userName" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="password"&gt;&lt;spring:message code="label.password" /&gt;&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:password path="password" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="submit" value="&lt;spring:message code="label.adduser" /&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;
  </code></pre>