1 package example.filters; 2 3 import javax.servlet.*; 4 import javax.servlet.http.*; 5 import java.io.IOException ; 6 7 import java.util.logging.Logger ; 8 import java.util.logging.Level ; 9 12 13 public class ExampleResponseHeadersFilter implements Filter { 14 private static final Logger log = Logger.getLogger("example.filters.ExampleResponseHeadersFilter"); 15 16 21 public void init(FilterConfig config) 22 throws ServletException 23 { 24 ServletContext app = config.getServletContext(); 25 26 String myParam = config.getInitParameter("my-param"); 28 if (log.isLoggable(Level.CONFIG)) 29 log.log(Level.CONFIG,"my-param value is `" + myParam + "'"); 30 } 31 32 39 public void doFilter(ServletRequest request, ServletResponse response, 40 FilterChain nextFilter) 41 throws ServletException, IOException 42 { 43 HttpServletRequest req = (HttpServletRequest) request; 44 HttpServletResponse res = (HttpServletResponse) response; 45 46 47 nextFilter.doFilter(req, res); 49 50 53 log.log(Level.FINER,"setting response headers to stop browser caching"); 55 56 res.setHeader("Cache-Control","no-cache,post-check=0,pre-check=0,no-store"); 57 res.setHeader("Pragma","no-cache"); 58 res.setHeader("Expires","Thu,01Dec199416:00:00GMT"); 59 } 60 61 65 66 public void destroy() 67 { 68 } 69 } 70 | Popular Tags |