Tomcat ExpiresFilter无法正常工作

时间:2013-07-11 07:51:27

标签: tomcat tomcat7

我无法让Tomcat使用正确的过期定义发送图像。浏览器继续发送已下载图像的获取请求,Tomcat以304响应。我想要的是Tomcat将使用正确的expires头响应初始请求,并且没有任何Last-modified头,因此浏览器将使用本地缓存直到文件没有到每个页面加载的服务器到期,看看图像是否已经改变。

我的web.xml文件中有以下定义:

<filter>
    <filter-name>ExpiresFilter</filter-name>
    <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
    <init-param>
        <param-name>ExpiresByType image</param-name>
        <param-value>access plus 1 weeks</param-value>
    </init-param>
    <init-param>
        <param-name>ExpiresByType text/css</param-name>
        <param-value>modification plus 0 minutes</param-value>
    </init-param>
    <init-param>
        <param-name>ExpiresByType application/javascript</param-name>
        <param-value>modification plus 0 minutes</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>ExpiresFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping> 

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

您是否可以按Container Provided Filters > ExpiresFilter > Troubleshooting

中所述启用ExpiresFilter日志

将以下声明添加到$CATALINA_BASE/conf/logging.properties

org.apache.catalina.filters.ExpiresFilter.level = FINE

您将看到日志消息,如下所示:

添加了过期标头:

Mar 26, 2010 2:09:47 PM org.apache.catalina.filters.ExpiresFilter onBeforeWriteResponseBody
  FINE: Request "/tomcat.gif" with response status "200"
  content-type "image/gif", set expiration date 3/26/10 2:19 PM

未添加过期标头:

Mar 26, 2010 2:10:27 PM org.apache.catalina.filters.ExpiresFilter onBeforeWriteResponseBody
  FINE: Request "/docs/config/manager.html" with response status "200"
  content-type "text/html", no expiration configured