退出后显示登录屏幕的后退按钮

时间:2018-03-20 08:11:41

标签: java servlet-filters

我知道已经标记了重复的问题,但这些方法似乎都不适用于我。请说明什么是错的。这是我的过滤器代码。

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    HttpSession session = request.getSession(false);
    if(session != null) 
    {
        session.invalidate(); 
    }  

    response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
    response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
    response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
    response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility

    request.getRequestDispatcher("login.jsf").forward(request, response);

    chain.doFilter(req, res);
}

1 个答案:

答案 0 :(得分:0)

默认情况下,现代浏览器在单击后退按钮后不会重新加载页面,除非您有一些强制重新加载的客户端代码。我的意思是,当您单击后退时,浏览器将不会为登录页面调用服务器。有关详细信息,请参阅:https://stackoverflow.com/a/8861236/5468990