public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (debug) {
log("SessionTimeoutFilter:doFilter()");
}
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
doBeforeProcessing(request, response);
HttpSession session = req.getSession();
//用户超时或没有登陆时跳转到登陆页面
logger.debug("before doFilter****");
String uri = req.getRequestURI();
if (uri.indexOf("sessiontimeout")==-1&&uri.indexOf("SysConfig")==-1&&(session.getAttribute("UserName") == null || session.isNew())) {
resp.sendRedirect(req.getContextPath()+"/sessiontimeout.jsp");
//resp.sendRedirect(req.getContextPath()+"/sessiontimeout.jsp"); 不能使用相对路径,不同的页面过来,相对路径会不同
return;
}
Throwable problem = null;
try {
chain.doFilter(request, response);
} catch (Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that.
problem = t;
t.printStackTrace();
}
logger.debug("after doFilter****");
doAfterProcessing(request, response);
// If there was a problem, we want to rethrow it if it is
// a known type, otherwise log it.
if (problem != null) {
if (problem instanceof ServletException) {
throw (ServletException) problem;
}
if (problem instanceof IOException) {
throw (IOException) problem;
}
sendProcessingError(problem, response);
}
}
FilterChain chain)
throws IOException, ServletException {
if (debug) {
log("SessionTimeoutFilter:doFilter()");
}
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
doBeforeProcessing(request, response);
HttpSession session = req.getSession();
//用户超时或没有登陆时跳转到登陆页面
logger.debug("before doFilter****");
String uri = req.getRequestURI();
if (uri.indexOf("sessiontimeout")==-1&&uri.indexOf("SysConfig")==-1&&(session.getAttribute("UserName") == null || session.isNew())) {
resp.sendRedirect(req.getContextPath()+"/sessiontimeout.jsp");
//resp.sendRedirect(req.getContextPath()+"/sessiontimeout.jsp"); 不能使用相对路径,不同的页面过来,相对路径会不同
return;
}
Throwable problem = null;
try {
chain.doFilter(request, response);
} catch (Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that.
problem = t;
t.printStackTrace();
}
logger.debug("after doFilter****");
doAfterProcessing(request, response);
// If there was a problem, we want to rethrow it if it is
// a known type, otherwise log it.
if (problem != null) {
if (problem instanceof ServletException) {
throw (ServletException) problem;
}
if (problem instanceof IOException) {
throw (IOException) problem;
}
sendProcessingError(problem, response);
}
}