[技巧篇]18.过滤器编写一个刷新用户端最新缓存的

public class NocacheFilter implements Filter {
    
    public void doFilter(ServletRequest request,
            ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        
        HttpServletResponse httpResponse = (HttpServletResponse)response;
        httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
        httpResponse.setHeader("Pragma", "no-cache");
        httpResponse.setDateHeader("Expires", 0);
        
        chain.doFilter(request, response);
    }
    
    public void destroy() {}
    public void init(FilterConfig fConfig) throws ServletException {}
}

这个我就是备注一下,就不发布了,需要在web.xml中注册一下或者使用Servlet3.0的版本@WebFilter

posted on 2015-10-09 11:14  胖先生  阅读(173)  评论(0编辑  收藏  举报