美文网首页
2018-03-04 Filter类(二):实现全站禁止缓存

2018-03-04 Filter类(二):实现全站禁止缓存

作者: 紫杉叶子 | 来源:发表于2018-03-07 13:21 被阅读0次
    笔记如下
    • web.xml
      作用全.jsp页面
    <filter>
        <filter-name>NoCacheFilter</filter-name>
        <filter-class>com.chen.demo2.NoCacheFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>NoCacheFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
      </filter-mapping>
    
    • NoCacheFilter
    
        //设置全站不缓存
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            // TODO Auto-generated method stub
            
            HttpServletRequest request2 = (HttpServletRequest)request;
            HttpServletResponse response2 = (HttpServletResponse) response;
            
            response2.setHeader("cache-control", "no-cache");
            response2.setHeader("pragma", "no-cache");
            response2.setDateHeader("expires", 0);
            chain.doFilter(request2, response2);
            
        }
    

    相关文章

      网友评论

          本文标题:2018-03-04 Filter类(二):实现全站禁止缓存

          本文链接:https://www.haomeiwen.com/subject/fgwffftx.html