-1

I have configured my session timeout in the server and have added a filter to handle session timeout. But when I am trying to redirect it back to the login page its not working. I searched the net but not getting anything solid. I am using jsf.. my code

public class SessionTimeoutFilter implements Filter {

private String timeoutPage = "login.seam";
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, 
  ServletResponse response, FilterChain filterChain) throws IOException,ServletException {
if ((request instanceof HttpServletRequest) 
   && (response instanceof HttpServletResponse)) 
{
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    if (isSessionControlRequiredForThisResource(httpServletRequest)) {
        if (isSessionInvalid(httpServletRequest)) 
        {
            String timeoutUrl = httpServletRequest.getContextPath() 
           + "/" + getTimeoutPage();
            System.out.println("Session is invalid! redirecting to timeoutpage : " + timeoutUrl);
            httpServletResponse.sendRedirect(timeoutUrl);
            return;
        }
    }
}
filterChain.doFilter(request, response);
}

Can anyone tell me what am i doing wrong... why is sendredirect not responding

zDroid
  • 426
  • 1
  • 11
  • 32

1 Answers1

0

Maybe this solution will be proper for your needs:

How to redirect to index page if session time out happened in jsf application

if you need perform some action on session timeout you can also create @Destory annotated method on session statefull bean.

Community
  • 1
  • 1