title: Default objects in spring 3 mvc SessionAttributes when session expired
body: <p>I think im confused a bit about session annotation in spring mvc.</p>
  
  <p>I have code like this (2 steps form sample, step 1 user data, step 2 address)</p>
  
  <pre><code>@SessionAttributes({"user", "address"})
  public class UserFormController {
  
      @RequestMapping(method = RequestMethod.GET)
      public ModelAndView show( ModelAndView mv ){
          mv.addObject( new User() );
          mv.addObject( new Address() );
          mv.setViewName("user_add_page");
          return mv;
      }
  
      @RequestMapping(method = RequestMethod.POST)
      public String processForm( User user, BindingResult result ){
          new UserValidator().validate(user, result);
          if( result.hasErrors() ){
              return "user_add_page";
          }else{
              return "redirect:/user_form/user_add_address";
          }
  
  // .........
  }
  </code></pre>
  
  <p>Now if i submit page after my session expires i get error</p>
  
  <blockquote>
    <p>org.springframework.web.HttpSessionRequiredException:
    Session attribute 'user' required -
    not found in session</p>
  </blockquote>
  
  <p>How do i handle it? i would like to have 2 options</p>
  
  <ol>
  <li>i create empty objects if missing in session and accept submit</li>
  <li>i forward back to user form with some message</li>
  </ol>
  
  <p>Im still in early stage of learning Spring so sorry if its something very obvious, i just cant see it.</p>
  
  <p>ps. is that even the good way to solve this kind of form in spring mvc or would you recomment different approach?</p>