- package www.csdn.dbshop.filter;
- 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 CacheFilter implements Filter
- {
- public void init(FilterConfig filterConfig) throws ServletException
- {
- System.out.println("初始化");
- }
- public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException
- {
- // response对象
- HttpServletResponse res = (HttpServletResponse) response;
- // 设定网页的到期时间,一旦过期则必须到服务器上重新调用
- res.setDateHeader("Expires", -1);
- // Cache-Control 指定请求和响应应遵循的缓存机制 no-cache指示请求或响应消息是不能缓存的
- res.setHeader("Cache-Control", "no-cache");
- // 用于设定禁止浏览器从本地缓存中调用页面内容,设定后一旦离开页面就无法从Cache中再调出
- res.setHeader("Pragma", "no-cache");
- // 放行
- chain.doFilter(request, res);
- }
- public void destroy()
- {
- System.out.println("销毁");
- }
- }
- 原帖地址:http://blog.csdn.net/qxs965266509/article/details/8848856
转载于:https://blog.51cto.com/woshixy/1186427