我有蒙山會話超時檢查Servlet過濾器:Servlet過濾器會話超時問題
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse res = (HttpServletResponse) servletResponse;
String uri = req.getRequestURI();
if (req.getUserPrincipal() == null && !uri.endsWith("login.xhtml") && uri.endsWith("xhtml")) {
res.reset();
res.setHeader("Location", "/nsi/faces/login.xhtml");
res.setStatus(HttpServletResponse.SC_FOUND);
res.setContentType("xhtml");
// filterChain.doFilter(servletRequest, servletResponse);
// req.getServletContext().getRequestDispatcher("/faces/login.xhtml").forward(req, res);
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
}
爲什麼當會話超時重定向不工作?我嘗試使用HttpServletResponse.sendRedirect和HttpServletResponse轉發。 P.s.獲取請求重定向,但POST請求進入方法並且什麼都不做;
這種方法拋出顯示java.lang.NullPointerException – 2015-03-19 13:02:34