Search code examples
servletsstruts2servlet-filters

Filter is not invoked for files outside /WEB-INF folder


Everything is fine on localhost! Using Tomcat 7.0.53, having the css, JS, images resources out of WEB-INF folder.

Accessing them like this :

${pageContext.request.contextPath}/resources/css/file.css

In the web.xml file I have a filter which is trying to set response header for those resource files

<filter>
<filter-name>theFilter</filter-name>
<filter-class>packages.theFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>theFilter</filter-name>
<url-pattern>/ressources/*</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.jpg</url-pattern>
<url-pattern>*.jpeg</url-pattern>    
<url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern>
</filter-mapping>

As I said it works fine on localhost. Once online the filter caches only Declared Servlet Urls!

Must say that I have 2 others filter needed for the app to work, cause I'm using Struts2 3.16.3

I tried many combinations with the url-patterns (one with /resources/* , or only the *.extension but still have the same problem)

Any idea what is wrong here?

My app uses HTTPS


Solution

  • Try

    <url-pattern>/*</url-pattern>
    

    This will at least identify where the root of the problem lies.