title: Spring form errors
body: <p>I have a problem with using spring form to login, I know what is the problem but I can not fix it.
  This is my code:</p>
  
  <pre><code>My Login.java
      package com.fsoft.entity;
  
  import org.hibernate.validator.constraints.NotEmpty;
  
  public class Login {
      @NotEmpty(message = "Please enter your username")
      private String username;
      @NotEmpty(message = "Please enter your password")
      private String password;
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  }
  </code></pre>
  
  <p>My Student.java</p>
  
  <pre><code>package com.fsoft.entity;
  
  import javax.validation.constraints.NotNull;
  
  import org.hibernate.validator.constraints.Email;
  
  public class Student {
      @NotNull(message = "Please enter student username")
      private String username;
      @NotNull(message = "Please enter student password")
      private String password;
      @NotNull(message = "Please enter student name")
      private String name;
      @NotNull(message = "Please enter student birth date")
      private String dob;
      @NotNull(message = "Please enter student email")
      @Email(message = "Email is invalid")
      private String email;
      @NotNull(message = "Please enter student age")
      private String age;
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getDob() {
          return dob;
      }
  
      public void setDob(String dob) {
          this.dob = dob;
      }
  
      public String getAge() {
          return age;
      }
  
      public void setAge(String age) {
          this.age = age;
      }
  
  }
  </code></pre>
  
  <p>This is the Controller:</p>
  
  <pre><code>package com.fsoft.springmvc;
  
  import javax.validation.Valid;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  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 com.fsoft.entity.Login;
  import com.fsoft.entity.Student;
  
  /**
   * Handles requests for the application home page.
   */
  @Controller
  public class HomeController {
      private static final String LOGIN = "Login";
      private static final String SUBMIT = "Submit";
  
      /**
       * Simply selects the home view to render by returning its name.
       */
      @RequestMapping(method = RequestMethod.GET)
      public String home(@ModelAttribute("Login") Login login) {
          return "Login";
      }
  
      @RequestMapping(value = "Login", method = RequestMethod.POST)
      public String Login(@ModelAttribute("Login") @Valid Login login, BindingResult result,
              @RequestParam("action") String action, ModelMap model) {
          String returnpage = "Register";
          if (LOGIN.equals(action)) {
              if (result.hasErrors()) {
                  returnpage = "Login";
              }
          }
          return returnpage;
      }
  
      @RequestMapping(value = "/gotoregister", method = RequestMethod.GET)
      public String registerpage(@ModelAttribute("registration") Student student) {
          return "Register";
      }
  
      @RequestMapping(value = "register", method = RequestMethod.POST)
      public String regis(@ModelAttribute("registration") @Valid Student student, @RequestParam("action") String action,
              BindingResult result) {
          String returnpage = "/Register";
          if (SUBMIT.equals(action)) {
              if (result.hasErrors()) {
              }
          }
          return returnpage;
      }
  }
  </code></pre>
  
  <p>My Login Page</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@ page session="false"%&gt;
  &lt;html&gt;
  
  
  &lt;head&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form:form action="Login" method="post" modelAttribute="Login"&gt;
          &lt;div class='form-horizontal well' style="width: 300px"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;User Name&lt;/label&gt;
                  &lt;form:input path="username" type="text" class="form-control"
                      id="username" name="username" placeholder="User Name"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="username" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Password&lt;/label&gt;
                  &lt;form:input path="password" type="password" class="form-control"
                      id="password" placeholder="Password" name="password"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="password" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-default" name="action"
                  value="Login"&gt;Login&lt;/button&gt;
          &lt;/div&gt;
      &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;link rel="stylesheet"
      href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
  
  &lt;!-- jQuery library --&gt;
  &lt;script
      src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;!-- Latest compiled JavaScript --&gt;
  &lt;script
      src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Registration Page</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@ page session="false"%&gt;
  &lt;html&gt;
  &lt;link rel="stylesheet"
      href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
  
  &lt;!-- jQuery library --&gt;
  &lt;script
      src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;!-- Latest compiled JavaScript --&gt;
  &lt;script
      src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;head&gt;
  &lt;title&gt;Registration&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;form:form action="register" method="post"
          modelAttribute="registration"&gt;
          &lt;div class='form-horizontal well' style="width: 800px"&gt;
              &lt;h3&gt;Hello : ${Login.username}&lt;/h3&gt;
              &lt;h3&gt;Registration Page&lt;/h3&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;User Name&lt;/label&gt;
                  &lt;form:input path="username" type="text" class="form-control"
                      id="username" name="username" placeholder="User Name"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="username" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Password&lt;/label&gt;
                  &lt;form:input path="password" type="password" class="form-control"
                      id="password" placeholder="Password" name="Password"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="password" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Email&lt;/label&gt;
                  &lt;form:input path="email" type="email" class="form-control"
                      id="email" name="email" placeholder="Email"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="email" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Name&lt;/label&gt;
                  &lt;form:input path="name" type="text" class="form-control" id="name"
                      placeholder="Name" name="name"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="name" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Date of Birth&lt;/label&gt;
                  &lt;form:input path="dob" type="text" class="form-control" id="dob"
                      name="dob" placeholder="Date of Birth"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="dob" cssClass="error" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Age&lt;/label&gt;
                  &lt;form:input path="age" type="number" class="form-control" id="age"
                      placeholder="Age" name="age"&gt;&lt;/form:input&gt;
                  &lt;form:errors path="age" cssClass="error" /&gt;
  
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-default" value="Submit"&gt;Submit&lt;/button&gt;
          &lt;/div&gt;
      &lt;/form:form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is when user login success, I call the registration page but the model attribute is not called so this error will show:</p>
  
  <pre><code> Neither BindingResult nor plain target object for bean name 'registration' available as request attribute
  </code></pre>