views:

30

answers:

1

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?

A: 

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"/>"/>
dwb