<filter> <filter-name>NoCache</filter-name> <filter-class>com.sys.common.Filters.ResponseHeaderFilter </filter-class> <init-param> <param-name>Cache-Control</param-name> <param-value>no-cache, must-revalidate</param-value> </init-param> </filter>
缓存文件一周
<filter> <filter-name>CacheForWeek</filter-name> <filter-class>com.sys.common.Filters.ResponseHeaderFilter </filter-class> <init-param> <param-name>Cache-Control</param-name> <param-value>max-age=604800, public</param-value> </init-param> </filter> <filter-mapping> <filter-name>CacheForWeek</filter-name> <url-pattern>/images/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CacheForWeek</filter-name> <url-pattern>*.js</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CacheForWeek</filter-name> <url-pattern>*.css</url-pattern> </filter-mapping>
自定义的filter:
public class ResponseHeaderFilter implements Filter { FilterConfig fc; public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) res; for (Enumeration e = fc.getInitParameterNames(); e.hasMoreElements();) { String headerName = (String) e.nextElement(); response.addHeader(headerName, fc.getInitParameter(headerName)); } chain.doFilter(req, response); } public void init(FilterConfig filterConfig) { this.fc = filterConfig; } public void destroy() { this.fc = null; } }
以上这篇JSP过滤器Filter配置过滤类型全部汇总就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章: