JSF,会话超时处理

时间:2014-04-18 07:13:09

标签: jsf session-timeout

我已在服务器中配置了会话超时,并添加了一个过滤器来处理会话超时。但是,当我尝试将其重定向回登录页面时,它无法正常工作。我在网上搜索但没有得到任何结果。我正在使用jsf ..我的代码

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);
}

任何人都可以告诉我,我做错了什么...为什么sendredirect没有回复

1 个答案:

答案 0 :(得分:0)

也许这个解决方案适合您的需求:

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

如果您需要对会话超时执行某些操作,您还可以在会话状态bean上创建@Destory注释方法。