title: Spring MVC: How to remove session attribute?
body: <p>Example of using <code>@SessionAttributes</code> below. How to clear <code>user</code> session attribute after wizard finished ? In my example after returning to <code>/wizard0</code> session attribute still exists. I've tried <code>status.setComplete()</code> and <code>session.removeAttribute("user")</code> but it doesn't work.</p>
  
  <pre><code>@Controller
  @SessionAttributes("user")
  public class UserWizard {
  
      @RequestMapping(value = "/wizard0", method = RequestMethod.GET)
      public String page1(Model model) {
          if(!model.containsAttribute("user")) {
              model.addAttribute("user", new User());
          }
          return "wizard/page1";
      }
  
      @RequestMapping(value = "/wizard1", method = RequestMethod.GET)
      public String page2(@ModelAttribute User user) {
          user.setFirstname(Utils.randomString());
          return "wizard/page2";
      }
  
      @RequestMapping(value = "/wizard2", method = RequestMethod.GET)
      public String page3(@ModelAttribute User user) {
          user.setLastname(Utils.randomString());
          return "wizard/page3";
      }
  
      @RequestMapping(value = "/finish", method = RequestMethod.GET)
      public String page4(@ModelAttribute User user, HttpSession session, SessionStatus status) {
          /**
           * store User ...
           */
          status.setComplete();
          session.removeAttribute("user");
          return "redirect:/home";
      }
  
  }
  </code></pre>
  
  <h2><strong>EDIT</strong></h2>
  
  <p>My mistake. <code>status.setComplete();</code> works good. <code>session.removeAttribute("user")</code> is nothing to do here.</p>