在tomcat7下面 利用ExpiresFilter来控制静态文件缓存很方便,按照tomcat官网手动配置即可:
但是tomcat6 里面并没有
org.apache.catalina.filters.ExpiresFilter
这个接口类。
解决办法如下:引入 ExpiresFilter-1.0.0.jar
下载jar:
http://files.cnblogs.com/files/qiaoyihang/ExpiresFilter-1.0.0.zip
下载源码:
https://github.com/bnegrao/ExpiresFilter
然后更改配置如下:
<filter>
<filter-name>ExpiresFilter</filter-name>
<filter-class>bnegrao.filters.ExpiresFilter</filter-class>
<init-param>
<param-name>ExpiresByType image</param-name>
<param-value>access plus 10 minutes</param-value>
</init-param>
<init-param>
<param-name>ExpiresByType text/css</param-name>
<param-value>access plus 10 minutes</param-value>
</init-param>
<init-param>
<param-name>ExpiresByType application/javascript</param-name>
<param-value>access plus 10 minutes</param-value>
</init-param>
</filter>
...
<filter-mapping>
<filter-name>ExpiresFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>