title: How to go back to the same JSP page in Spring MVC with the same values
body: <p>Please help me on this. Below is my LoginController class where I pass the username and password from a JSP and then validate and display the to do list of the username in diffrent jsp page. </p>
  
  <p>Here is my code</p>
  
  <p>LoginController.class</p>
  
  <pre><code>  @RequestMapping(value = "/loginvalidate")
    public String validatelogin(LoginForm request, ModelMap map) throws Exception {
      String userName = request.getUserName();
      sessionUser.setUserName(userName);
      map.addAttribute("user", sessionUser.getUserName());
      map.addAttribute("dateTime", sessionscopebillingdata.getDate());
      System.out.println("username from the controller class " + sessionUser.getUserName());
      List result = loginservice.ValidateLogin(request);
      map.addAttribute("ToDoList", result);
      return "UserToDoList";
   } 
  </code></pre>
  
  <p>Here is my UserToDoList.jsp</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Home&lt;/title&gt;
  &lt;div class="inset"&gt;
      &lt;%=session.getAttribute("dateTime")%&gt;
      &lt;h2&gt; TO DO LIST &lt;/h2&gt;        
      &lt;%=session.getAttribute("user")%&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css"/&gt;
  &lt;/head&gt;    
  &lt;body&gt;
      &lt;form action="logout" method="POST"&gt;
          &lt;button type="submit"&gt;Logout&lt;/button&gt;    
      &lt;/form&gt;        
  
      &lt;form name="Add" action="Adduser" method="post"&gt;
          &lt;button type="submit"&gt;ADD&lt;/button&gt; 
  
      &lt;/form&gt;
      &lt;/link&gt;
      &lt;form:form&gt;
  
          &lt;c:if test="${not empty ToDoList}"&gt;
  
              &lt;table&gt;
  
                  &lt;tr&gt;&lt;th&gt;LOGIN ID&lt;/th&gt;
                      &lt;th&gt;LAST UPDATE BY&lt;/th&gt;
                      &lt;th&gt;TRANSACTION TYPE&lt;/th&gt;
                      &lt;th&gt;STATUS&lt;/th&gt;
                  &lt;/tr&gt;    
                  &lt;c:forEach var="item" items="${ToDoList}"&gt;
                      &lt;tr&gt;   &lt;td&gt;${item[0]}&lt;/td&gt;
                          &lt;td&gt;${item[1]}&lt;/td&gt;
                          &lt;td&gt;${item[2]}&lt;/td&gt;   
                          &lt;td&gt;${item[3]}&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/c:forEach&gt;
  
              &lt;/table&gt;
  
          &lt;/c:if&gt;
  
  
      &lt;/form:form&gt;
  
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>From the above JSP if I click the "Add" button  then it will goes to the below JSP</p>
  
  <p>AddUser.jsp</p>
  
  <pre><code>&lt;form:form method="POST" name="LoginForm" modelAttribute="roleId" action="adduser"&gt; 
   &lt;ul&gt;
      &lt;li&gt;
          &lt;label&gt;User Name&lt;/label&gt; &lt;input type="text" name="userName" /&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;label&gt;Password&lt;/label&gt; &lt;input type="text" name="passWord" /&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;label&gt;Approver &lt;/label&gt; &lt;input type="text" name="approver" /&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;label&gt;User Role &lt;/label&gt;
          &lt;form:select path="userRole" items="${Codes}" tabindex="50"&gt;
              &lt;form:option value="----------Please select---------" /&gt;
              &lt;form:option value="${role.id}" /&gt;
              &lt;form:option value="${role.codeValue}" /&gt; 
          &lt;/li&gt;
      &lt;/form:select&gt;
    &lt;/ul&gt;  
  
  
   &lt;input type="submit" value="Submit"&gt; 
  
  &lt;/form:form&gt;  
  </code></pre>
  
  <p>From the above JSP if click submit then it will call the below method inside the same Logincontroller class and this is to add new users .</p>
  
  <p>Once new user added I want this method to go back to the same "UserToDoList.jsp" with the same output.
  How to achieve this , Please help.</p>
  
  <p>Below method is from LoginController.class</p>
  
  <pre><code>@RequestMapping(value = "/adduser")
  public String adduser(LoginForm request) throws Exception {
      String result = loginservice.adduser(request);
      return "/Adduser";
   }
  </code></pre>
  
  <p>Below id my bean to get the username</p>
  
  <pre><code>@Component
  @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
  
  public class BillingSessionScopeUser {
  
  public String userName;
  
  public String getUserName() {
      return userName;
  }
  
  public void setUserName(String userName) {
      this.userName = userName;
  }
  </code></pre>
  
  <p>}</p>