设置一个过滤器,将响应标头设置为仅图像文件

发布于 2024-09-27 18:17:02 字数 255 浏览 0 评论 0原文

根据我在此链接中的讨论,我遇到了缓存问题,

但是我我不知道如何处理在 Spring MVC 上设置响应标头的建议。

有谁知道如何设置某种过滤器,仅在图像文件上添加响应标头?

我目前不是使用 SPring MVC 进行 J2EE Web 开发的专家。

有什么想法吗?

I am having a caching problem based on the discussion that I have in this link

But I am not sure how to go about with the suggestion on setting the response headers on my Spring MVC.

Does anybody know how to setup a some sort of a filter that will add add a response header only on image files?

I currently am not an expert on J2EE web development with SPring MVC.

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-10-04 18:17:02

Spring 附带了一个资源 Servlet。

<!--  Serves static resource content from .jar files such as blartoch.jar  --> 
<servlet>
  <servlet-name>Resources Servlet</servlet-name> 
  <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class> 
  <load-on-startup>50</load-on-startup> 
</servlet>


<!-- Map all /resources requests to the Resource Servlet for handling -->
<servlet-mapping>
  <servlet-name>Resources Servlet</servlet-name>
  <url-pattern>/resources/*</url-pattern>
</servlet-mapping>

我们正在使用一个ear文件,我的所有资源都在耳朵的一个罐子里。如果您仅部署 WAR 文件(可能部署到 tomcat),则尝试将资源放入 jar 中,并将该 jar 放入 WAR 文件的 /WEB-INF/lib 目录中。

如果您将资源(在 jar 内)存储在以下目录中:

/META-INF/common/images

对资源的请求将如下所示:

<img src="<c:url value="/resources/common/images/cuteKitten.jpg"/>"/>

Spring comes with a Resources Servlet.

<!--  Serves static resource content from .jar files such as blartoch.jar  --> 
<servlet>
  <servlet-name>Resources Servlet</servlet-name> 
  <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class> 
  <load-on-startup>50</load-on-startup> 
</servlet>


<!-- Map all /resources requests to the Resource Servlet for handling -->
<servlet-mapping>
  <servlet-name>Resources Servlet</servlet-name>
  <url-pattern>/resources/*</url-pattern>
</servlet-mapping>

We are using an ear file and all of my resources are in a jar in the ear. If you are only deploying a WAR file (perhaps to tomcat), then try putting your resources in a jar and putting the jar in your WAR file's /WEB-INF/lib directory.

If you store your resources (inside the jar) in the following directory:

/META-INF/common/images

requests for your resources will look something like this:

<img src="<c:url value="/resources/common/images/cuteKitten.jpg"/>"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文