我正在使用过滤器检查用户是否登录,然后不缓存上一页。这个代码是这样的,
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
....
if (isRegisteredUser.equalsIgnoreCase(("1"))) {
sessionID = UUID.randomUUID().toString();
session.setMaxInactiveInterval(1800);
Cookie userCookie = new Cookie("userCookie", "loginUser");
userCookie.setPath("/");
httpServletResponse.addCookie(userCookie);
Cookie sessionCookie = new Cookie("WITSessionCookie", sessionID);
sessionCookie.setMaxAge(60*30);
sessionCookie.setPath("/");
httpServletResponse.addCookie(sessionCookie);
if (!httpServletRequest.getRequestURI().startsWith(httpServletRequest.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
httpServletResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpServletResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpServletResponse.setDateHeader("Expires", 0); // Proxies.
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
...
} //end of doFilter()
但问题是,如果用户在任何页面上单击任何按钮或链接,并且该操作返回 null,然后单击浏览器后退按钮,则显示页面已过期。我怎样才能防止这种情况?很好,该页面没有缓存,但是为什么当我单击任何按钮或任何链接并为该操作返回 null 时它会使我的页面过期?
谢谢