注销后单击后退按钮显示上一页

时间:2014-11-07 12:02:19

标签: jsf-2.2

我在我的网络应用程序中使用apache shiro。我不希望在注销后显示上一页,因此我使用dofilter进行缓存禁用,但它不起作用。 下面是我试过的代码。这有什么问题吗?让我知道。

Java代码

 import java.io.IOException;
            import javax.servlet.Filter;
            import javax.servlet.FilterChain;
            import javax.servlet.FilterConfig;
            import javax.servlet.ServletException;
            import javax.servlet.ServletRequest;
            import javax.servlet.ServletResponse;
            import javax.servlet.http.HttpServletResponse;

            public class CacheControlPhaseListener implements Filter {

                @Override
                public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

         HttpServletResponse response = (HttpServletResponse) res;
           response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 
               response.setHeader("Pragma", "no-cache"); 
                        response.setDateHeader("Expires", 0);                               chain.doFilter(req, res);      

                }

                @Override
                public void destroy() {
                    // TODO Auto-generated method stub

                }

                @Override
                public void init(FilterConfig arg0) throws ServletException {
                    // TODO Auto-generated method stub

                }
            }

的web.xml

<filter> 
    <filter-name>CacheControlPhaseListener</filter-name>
        <filter-class> 
        au.com.bytecode.controller.CacheControlPhaseListener
        </filter-class> 
    </filter>

    <filter-mapping>     
        <filter-name>CacheControlPhaseListener</filter-name>     
        <url-pattern>*.xhtml</url-pattern>   
    </filter-mapping>

    <filter-mapping>     
        <filter-name>CacheControlPhaseListener</filter-name>     
        <url-pattern>*.jsf</url-pattern>     
    </filter-mapping>



**Shiro ini**
[main]    
    authc.loginUrl = /login.xhtml
    authc.usernameParam = USERNAME
    authc.passwordParam = USERPASSWORD
    authc.rememberMeParam = rememberMe
    user.loginUrl = /login.xhtml

    [users]
    admin=admin
    [urls]
    /login.xhtml = anon

1 个答案:

答案 0 :(得分:0)

您看到的页面在浏览器级别缓存。如果您尝试发布表单等,那么您将获得登录页面。如果您不希望浏览器存储您的页面,请使用

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

作为<html>代码

之后的第一行