我在这里添加了我的代码
https://gist.github.com/priyankahdp/be578a92f55d29702928在我的控制台中没有显示错误。但是在会话超时后没有页面重定向。但它被称为SessionTimeoutFilter class doFilter()方法当任何表单活动调用
但是页面浏览量和前面一样没有重定向
请帮我解决这个问题
谢谢
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;
}
这是完美的工作:-)
特别感谢亲爱的朋友蓝海