gpt4 book ai didi

Tomcat ExpiresFilter 无法正常工作

转载 作者:行者123 更新时间:2023-11-28 21:47:53 25 4
gpt4 key购买 nike

我无法让 Tomcat 发送具有正确过期定义的图像。浏览器不断发送对已下载图像的获取请求,Tomcat 以 304 响应。我想要的是 Tomcat 将使用适当的过期 header 响应初始请求并且没有任何 Last-modified header ,因此浏览器将使用本地缓存直到文件过期而无需在每次加载页面时都去服务器查看图像是否已更改。

我的 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>

有什么想法吗?

最佳答案

您能否按照 Container Provided Filters > ExpiresFilter > Troubleshooting 中的描述启用 ExpiresFilter 日志? :

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

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

您将看到如下日志消息:

添加了过期 header :

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

没有添加过期 header :

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

关于Tomcat ExpiresFilter 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17587878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com