title: Getting HttpSession object null
body: <p>I am using Spring web mvc , rest api, and front end as angular 2. I am creating session in spring using HttpSession, it set the object in session but when I retrieve the session attribute, it returns null. Below is my code. Any help will be appreciated.</p>
  
  <pre><code>@RequestMapping(value="/getSession", method=RequestMethod.GET)
      public @ResponseBody User getSession(HttpSession session,HttpServletRequest req){
          // session = req.getSession(false);
          User user=(User) session.getAttribute("name");
          System.out.println("name "+user.getName());
          System.out.println("surname "+user.getSurname());
          System.out.println("address "+user.getAddress());
          if(user!= null)
              return user;
          else
              return null;
      }
  
      @RequestMapping(value="userFormData.html",method = RequestMethod.POST)
      public String setUserForm(@ModelAttribute User user, HttpServletRequest ht, HttpSession session){
          HttpSession se = ht.getSession(true);
          se.setAttribute("name", user);
          String str="Vikram";
          System.out.println("Name "+str);
          List&lt;Address&gt; ad= user.getAddress();
          System.out.println("User");
          User user1=(User)se.getAttribute("name");
          System.out.println("SESSION :"+user1.getName());
          System.out.println("SESSION END :"+user1.getSurname());
          System.out.println(ad.size());
          return "user";
      }
  </code></pre>