2018-03-04 Filter类(三):指定缓存内容

笔记如下

  • web.xml
    指定图片可以缓存


    4.png
  • CacheFilter

//在禁止缓存情况下,可以自定义缓存的内容
    @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", "maxage-3600");
        response2.setDateHeader("expires", System.currentTimeMillis() + 1000*60*60);
        chain.doFilter(request2, response2);
    
    }

你可能感兴趣的:(2018-03-04 Filter类(三):指定缓存内容)