web.xml配置: 禁止游览器对动态内容做缓存

package com.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class ResponseHeaderFilter implements Filter {
    FilterConfig fc;

    public void doFilter(ServletRequest req, ServletResponse res,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        // set the provided HTTP response parameters
        Enumeration e = fc.getInitParameterNames();
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            response.addHeader(headerName, fc.getInitParameter(headerName));
        }
        // pass the request/response on
        chain.doFilter(req, response);
    }

    public void init(FilterConfig filterConfig) {
        this.fc = filterConfig;
    }

    public void destroy() {
        this.fc = null;
    }

}

在这里以.do结尾的请求均为动态请求
在web.xml中添加

    
        NoCache
        com.filter.ResponseHeaderFilter
        
            Cache-Control
            no-cache
        
        
            Pragma
            No-cache
        
        
            Expires
            0
        
    

    
        NoCache
        *.do
    
 ```
http://blog.csdn.net/liujin4049/article/details/3010370

你可能感兴趣的:(web.xml配置: 禁止游览器对动态内容做缓存)