title: Spring @SessionAttribute how to retrieve the session object in same controller
body: <p>I am using Spring 3.2.0 MVC. In that I have to store one object to session.
  Currently I am using HttpSession set and get attribute to store and retrieve the value.</p>
  
  <p>It returns only the String not Object. I want to use @SessionAttribute when I tried it sets the object in session but I could not retrieve the session object</p>
  
  <pre><code> @RequestMapping(value = "/sample-login", method = RequestMethod.POST)
      public String getLoginClient(HttpServletRequest request,ModelMap modelMap) {
          String userName = request.getParameter("userName");
          String password = request.getParameter("password");
          User user = sample.createClient(userName, password);
          modelMap.addAttribute("userObject", user);
          return "user";
      }
  
  
       @RequestMapping(value = "/user-byName", method = RequestMethod.GET)
      public
      @ResponseBody
      String getUserByName(HttpServletRequest request,@ModelAttribute User user) {
  
          String fas= user.toString();
          return fas;
      }
  </code></pre>
  
  <p>Both methods are in same controller. How would I use this to retrieve the object?</p>