I want to have the following method:
@ExceptionHandler(MyRuntimeException.class)
public String myRuntimeException(MyRuntimeException e, RedirectAttributes redire
Note that this is actually supported out-of-the-box by Spring 4.3.5+ (see SPR-14651 for more details).
I've managed to get it working using the RequestContextUtils class. My code looks like this
@ExceptionHandler(MyException.class)
public RedirectView handleMyException(MyException ex,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
String redirect = getRedirectUrl(currentHomepageId);
RedirectView rw = new RedirectView(redirect);
rw.setStatusCode(HttpStatus.MOVED_PERMANENTLY); // you might not need this
FlashMap outputFlashMap = RequestContextUtils.getOutputFlashMap(request);
if (outputFlashMap != null){
outputFlashMap.put("myAttribute", true);
}
return rw;
}
Then in the jsp page I simply access the attribute
Hope it helps!