title: Performing a redirect from a spring MVC @ExceptionHandler method
body: <p>I want to have the following method:</p>
  
  <pre><code>@ExceptionHandler(MyRuntimeException.class)
  public String myRuntimeException(MyRuntimeException e, RedirectAttributes redirectAttrs){//does not work
      redirectAttrs.addFlashAttribute("error", e);
      return "redirect:someView";
  }
  </code></pre>
  
  <p>I get a:</p>
  
  <pre><code>java.lang.IllegalStateException: No suitable resolver for argument [1] type=org.springframework.web.servlet.mvc.support.RedirectAttributes]
  </code></pre>
  
  <p>Is there a way to perform a redirect from an <code>@ExceptionHandler</code>? Or maybe some way to circumvent this restriction?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I have modified my exception handler as follows:</p>
  
  <pre><code>@ExceptionHandler(InvalidTokenException.class)
  public ModelAndView invalidTokenException(InvalidTokenException e, HttpServletRequest request) {
  RedirectView redirectView = new RedirectView("signin");
  return new ModelAndView(redirectView , "message", "invalid token/member not found");//TODO:i18n
  }
  </code></pre>
  
  <p>This is the method that may throw the exception:</p>
  
  <pre><code>@RequestMapping(value = "/activateMember/{token}", method = RequestMethod.GET, produces = "text/html")
  public String activateMember(@PathVariable("token") String token) {
      signupService.activateMember(token);
      return "redirect:memberArea/index";
  }
  </code></pre>
  
  <p>The problem with my modified exception handler is that it systematically redirects me to the following URL:</p>
  
  <pre><code>http://localhost:8080/bignibou/activateMember/signin?message=invalid+token%2Fmember+not+found 
  </code></pre>
  
  <p>Instead of: </p>
  
  <pre><code>http://localhost:8080/bignibou/signin?message=invalid+token%2Fmember+not+found
  </code></pre>
  
  <p><strong>EDIT 2</strong>:</p>
  
  <p>Here is my modified handler method:  </p>
  
  <pre><code>@ExceptionHandler(InvalidTokenException.class)
  public String invalidTokenException(InvalidTokenException e, HttpSession session) {
  session.setAttribute("message", "invalid token/member not found");// TODO:i18n
  return "redirect:../signin";
  }
  </code></pre>
  
  <p>The problem I now have is that the message is stuck in the session...</p>