这个问题已经在这里有一个答案:
我已经在服务器中配置我的会话超时,并添加了一个过滤器来处理会话超时。但是,当我试图把它重定向到登录页面,它不工作。我搜索网,但没有得到任何固体。我使用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响应
也许这个解决方案将是适当的为您的需求:
How to redirect to index page if session time out happened in jsf application
如果您需要进行会话超时一些动作,你也可以创建会话bean的有状态的注释@Destory方法。