Tomcat ExpiresFilter 无法正常工作

编程入门 行业动态 更新时间:2024-10-10 16:19:24
本文介绍了Tomcat ExpiresFilter 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I can't get Tomcat to send images with the correct expires definition. The browser keep sending get requests for images already downloaded and Tomcat responds with 304. What I would want is that Tomcat will respond to the initial request with proper expires header and without any Last-modified header so the browser will use local cache until the file expires without going to the server each page load to see if the image had changed.

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

I have the following definition in my web.xml file:

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

有什么想法吗?

推荐答案

您能否按照 容器提供的过滤器 > ExpiresFilter > 故障排除 :

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

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

您将看到如下日志消息:

You will see log message such as the following:

添加了过期标头:

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

这篇关于Tomcat ExpiresFilter 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 04:08:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   Tomcat   ExpiresFilter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!