-1

I can not find any solutions for Spring to redirect to page together with parameters when session is timed out. I need to redirect to login page with error like "Session expired". I have tried filter and method session.isNew(). But it does not work since when request reaches login page it always already has session. Also HttpSessionEvent handler does not work because does not allow to access to request attributes and redirect to page.

ovod
  • 1,118
  • 4
  • 18
  • 33

1 Answers1

1

The easiest way would be to create an Interceptor that adds the Refresh header to every response with a time just after session expiry.

public class RefreshInterceptor extends HandlerInterceptorAdapter {

    @Override
    public void postHandle (
        HttpServletRequest request, 
        HttpServletResponse response, 
        Object handler, 
        ModelAndView modelAndView
    ) throws Exception {

      //if session != null and user is authenticated then...
      response.setIntHeader("Refresh", figureOutWhenSessionExpires() + A_SMALL_DELAY );

      super.postHandle(request, response, handler, modelAndView);

    }
}
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • But this will not redirect me to anyway but prolong session. And this is not what I want. – ovod Feb 06 '16 at 18:32
  • @ovod it tells the browser to reload the current page just after session expires. If the page is secured, the server will redirect the browser to the login page – Neil McGuigan Feb 06 '16 at 22:56