title: Spring MVC4 Session Management
body: <p>I am developing a small spring project in which the login page has two type of users admin and staff. on login attempt i want to apply session using spring MVC4 and also wants to open jsp based on the user role(Admin or Staff).
  the session has four/five fields like name,id,role,SessionId. i want these information to travel through the jsp pages. But i don't want to do this using url parameter passing. </p>
  
  <p>I don't know how to do this because i am new in spring and this is my first project. Help me Please.
  If someone can provide me the sample code and guide me on this then it would be very helpfull.</p>
  
  <p>// Login.jsp code</p>
  
  <pre><code>var MobileNo=$('#mobno').val();
              var StaffPwd=$('#pwd').val();
              $.ajax
              (
                      {
                      url: "http://localhost:8080/OnlineStore/kmsg/grocery/Login",
                      type: "POST",
                      data: {MobileNo: MobileNo,StaffPwd: StaffPwd},
                      success: function(data)
                      {
                          var vUserRole = data["UserRole"];
                          var vUserName = data["UserName"];
  
                          if(data==="")
                              {
                              alert("Login Failed");
                              }
                          else
                              {
                              if(vUserRole == "Admin")
                                  {
                                     alert("Login Success: " + vUserName);
                                     window.location.href = "http://localhost:8080/OnlineStore/JspPages/City.jsp";
                                  }
                              if(vUserRole == "CityAdmin")
                                  {
                                      alert("Login Success: " + vUserName);
                                       window.location.href = "http://localhost:8080/OnlineStore/JspPages/Locality.jsp";
                                  }
                              if(vUserRole == "Staff")
                                  {
                                      alert("Login Success: " + vUserName);
                                      window.location.href = "http://localhost:8080/OnlineStore/JspPages/CustomerOrder.jsp";
                                  }                           
                              }
                      },
                      error: function(e)
                      {
                      alert('Error:' +e)
                      }
                      }
              );
  </code></pre>
  
  <p>// this is controller code</p>
  
  <pre><code> @RequestMapping("/Login") 
  public @ResponseBody UserServiceModel selectStaff(@RequestParam Map&lt;String,String&gt; requestParams) throws Exception 
  { 
  String MobileNo = requestParams.get("MobileNo"); 
  String StaffPwd = requestParams.get("StaffPwd"); 
  return staffAdapter.login(MobileNo, StaffPwd); 
  }
  
  --------------
  </code></pre>
  
  <hr>