通过Filter设置HTTP hander中的cache-control
来源:互联网 发布:淘宝溢价是什么意思 编辑:程序博客网 时间:2024/05/21 09:50
<filter> <filter-name>cache-control</filter-name> <filter-class>com.hibtest6.filter.CacheControl</filter-class> <init-param> <param-name>.css</param-name> <param-value>520</param-value> </init-param> <init-param> <param-name>.gif</param-name> <param-value>520</param-value> </init-param> <init-param> <param-name>.js</param-name> <param-value>520</param-value> </init-param> </filter> <filter-mapping> <filter-name>cache-control</filter-name> <url-pattern>*.css</url-pattern> </filter-mapping> <filter-mapping> <filter-name>cache-control</filter-name> <url-pattern>*.gif</url-pattern> </filter-mapping> <filter-mapping> <filter-name>cache-control</filter-name> <url-pattern>*.js</url-pattern> </filter-mapping>
public class CacheControl implements Filter{private Map map = new HashMap<String, Long>();public void destroy() {System.out.println("destroy");}public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {HttpServletRequest httpServletRequest = (HttpServletRequest) request;String requestUri = httpServletRequest.getRequestURI();//SSH2/js/easyui.cssString cache = httpServletRequest.getHeader("cache-Control");if(requestUri.lastIndexOf(".")!=-1){String str = requestUri.substring(requestUri.lastIndexOf(".") , requestUri.length());Long strValue = (Long) map.get(str);if(strValue!=null){HttpServletResponse httpServletResponse = (HttpServletResponse) response;httpServletResponse.setHeader("Cache-Control", "max-age="+strValue);httpServletResponse.setDateHeader("Expires", System.currentTimeMillis()+strValue*1000);response = httpServletResponse;}}chain.doFilter(request, response);}public void init(FilterConfig filterConfig) throws ServletException {Enumeration enumeration = filterConfig.getInitParameterNames();while(enumeration.hasMoreElements()){String eleName = (String) enumeration.nextElement();if(eleName==null || eleName==""){continue;}String eleValue = filterConfig.getInitParameter(eleName);Long eleValueLong = Long.parseLong(eleValue); if(eleValueLong>0){map.put(eleName, eleValueLong);}}System.out.println(map);System.out.println("init");}}
0 0
- 通过Filter设置HTTP hander中的cache-control
- HTTP header中的 Cache-control
- HTTP header中的 Cache-control
- HTTP header中的Cache-Control
- HTTP header中的 Cache-control
- HTTP header中的Cache-control
- HTTP消息头中的“Cache-control”
- 【php】HTTP消息头中的“Cache-control”
- HTTP消息头中的“Cache-control”介绍
- HTTP消息头中的“Cache-control”介绍
- HTTP消息头中的“Cache-control”介绍
- HTTP消息头中的“Cache-control”介绍
- HTTP消息头中的“Cache-control”介绍
- http 头 Cache-control
- HTTP协议-Cache-Control
- http cache-control
- http Cache-control
- http cache-control 指令的设置以及意义
- 【L3_002】堆栈【线段树】
- php函数microtime
- JasperReport6.3.1官网下载
- 记第一次面试
- 国内随时接收发送谷歌邮箱
- 通过Filter设置HTTP hander中的cache-control
- Android Studio导入Android源码
- Java OOP day04
- 【L3_002】堆栈【线段树】
- 最终排名
- 【Linux】C语言位运算
- freetype+SDL+SDL_ttf移植及demo
- 静态变量(static)和实例变量的区别?
- 期权和股票