title: How do I pass ModelAttribute between Controllers?
body: <p>I'm trying to create a Home page with 2 functionalities:</p>
  
  <ol>
  <li>Login</li>
  <li>Sign Up</li>
  </ol>
  
  <p>I'm mapping each request to a different controller and trying to get the result back to my <code>home.jsp</code>. But I'm having trouble passing only certain specific <code>ModelAttribute</code> around, between Controllers. More specifically, i cant get the changed I make to the <code>ModelMap</code> and <code>BindingResult</code> in one controller to be reflected in others.</p>
  
  <p>I'm sure there's something <em>basically</em> wrong with what I'm doing. Please help.</p>
  
  <p>There are 2 forms in my <code>home.jsp</code>. One for Login:</p>
  
  <pre><code>&lt;form:form name="loginForm" modelAttribute="loginUser" action="login" method="post"&gt;
  
      Email: &lt;form:input name="loginEmail" id="loginEmail" value="" path="email"/&gt;
      &lt;form:errors path="email" cssClass="error" /&gt;
      &lt;br/&gt;
  
      password: &lt;form:password name="loginPassword" Id="loginPassword" value="" path="password" /&gt;
      &lt;form:errors path="password" /&gt;
      &lt;br/&gt;
  
      &lt;input type="submit" id="id_login" value="Login"&gt;
  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>and the other one for Sign Up:</p>
  
  <pre><code>&lt;form:form name="SignUpForm" modelAttribute="signUpUser" action="signup" method="post"&gt;
  
      Full Name: &lt;form:input name="name" id="name" value=""   path="name"/&gt;
      &lt;form:errors path="name" cssClass="error" /&gt;
      &lt;br/&gt;
  
      Email: &lt;form:input name="signupEmail" id="signupEmail" value="" path="email"/&gt;
      &lt;form:errors path="email" cssClass="error" /&gt;
      &lt;br/&gt;
  
      password: &lt;form:password name="signUpPassword" Id="signUpPassword" value="" path="password" /&gt;
      &lt;form:errors path="password" /&gt;
  
      &lt;input type="submit" id="id_signUp" value="Sign Up"&gt;
  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>I have 3 controllers: <code>HomeController.java</code>:</p>
  
  <pre><code>@RequestMapping("/home")
  public String showHome(ModelMap model,
          @ModelAttribute("loginUser") User loginUser,
          BindingResult loginResult,
          @ModelAttribute("signUpUser") User signUpUser,
          BindingResult signUpResult) {
      return "home";
  }
  </code></pre>
  
  <p><code>AuthenticationController.java</code>:</p>
  
  <pre><code>@RequestMapping("/login")
  public String login(@ModelAttribute("loginUser") User user,
          BindingResult result, ModelMap model, HttpServletRequest request,
          HttpServletResponse response) {
  
      loginFormValidator.validate(user, result);
  
      if(Errors in `result`)
          return "forward:/home";
  
      // Authentication Logic
      request.getSession().setAttribute("s_user_obj", some_variable);
      return "forward:/home";
  
  }
  </code></pre>
  
  <p>and <code>ProfileController.java</code>:</p>
  
  <pre><code>@RequestMapping("/signup")
  public String signUpUser(@ModelAttribute("signUpUser") User user,
          BindingResult result, ModelMap model) {
  // Do stuff related to Sign Up
  // Forward to home.jsp
      }
  </code></pre>
  
  <p>When the request is forwarded to <code>/home</code>, I'm getting same values in both <code>loginUser</code> and <code>signUpUser</code>. Worse, there are no errors i.e. the <code>result</code> variable is not reflecting the ones in the previous controllers.</p>
  
  <p>I'm sure there's a better way of doing this, this is a newbie's attempt at it. Please advice.</p>