这里我添加了我的代码
https://gist.github.com/priyankahdp/be578a92f55d29702928
我的控制台中没有显示错误。但会话超时后没有页面重定向。 但是当任何表单活动调用时,它被称为 SessionTimeoutFilter 类 doFilter()方法
但页面视图如前所述 没有重定向
请求帮助我解决这个问题
感谢
答案 0 :(得分:0)
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;
// is session expire control required for this request?
if (isSessionControlRequiredForThisResource(httpServletRequest)) {
// is session invalid?
if (isSessionInvalid(httpServletRequest)) {
/**/
String redirectURL = httpServletResponse.encodeRedirectURL(httpServletRequest.getContextPath() +"/"+ getTimeoutPage());
if (isAJAXRequest(httpServletRequest)) {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><partial-response><redirect url=\"").append(redirectURL).append("\"></redirect></partial-response>");
httpServletResponse.setHeader("Cache-Control", "no-cache");
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("text/xml");
PrintWriter pw = response.getWriter();
pw.println(sb.toString());
pw.flush();
}else{
String timeoutUrl = httpServletRequest.getContextPath()+ "/" + getTimeoutPage();
logger.info("session is invalid! redirecting to timeoutpage : "+ timeoutUrl);
httpServletResponse.sendRedirect(timeoutUrl);
}
return;
}
}
}
filterChain.doFilter(request, response);
}
private boolean isAJAXRequest(HttpServletRequest request) {
boolean check = false;
String facesRequest = request.getHeader("Faces-Request");
if (facesRequest != null && facesRequest.equals("partial/ajax")) {
check = true;
}
return check;
}
这完美地运作: - )
特别感谢亲爱的朋友Blue Ocean