I would like to write a Spring MVC HandlerInterceptorAdaptor which does different things in the postHandle() method based on wether the HttpResponse is a redirect or not.
Is this possible, and if so how?
public class MenuInterceptor extends HandlerInterceptorAdapter {
public final void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView) throws SystemException {
if (redirect) {
// do somethnig
} else {
// do something else
}
}
EDIT:
Is there a better way than this:
if (modelAndView.getView() instanceof RedirectView || modelAndView.getViewName().startsWith("redirect:")) {
// Do something
} else {
// Do something else
}
In Spring MVC, a controller typically sends a redirect by returning a
Viewthat is aRedirectViewor a String viewName that starts with theredirect:prefix. You can easily check for either of these.