java web中使 Browser 不缓存页面的过滤器(Filter - 2)

package OSChina;

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;


/**
* 用于的使 Browser 不缓存页面的过滤器
*/
public class FilterDemoTwo implements Filter{

 @Override
 public void destroy() {


 }

 @Override
 public void doFilter(ServletRequest request,
   ServletResponse response, FilterChain filterChain)
   throws IOException, ServletException {

   ((HttpServletResponse) response).setHeader("Cache-Control","no-cache");
     ((HttpServletResponse) response).setHeader("Pragma","no-cache");
     ((HttpServletResponse) response).setDateHeader ("Expires", -1);
     filterChain.doFilter(request, response);

 }

 @Override
 public void init(FilterConfig filterconfig) throws ServletException {


 }

}

你可能感兴趣的:(filter)