How to map a filter for a welcome file in web.xml for Tomcat?

I created Filterto check Cookiewith the request object and the forwardrequest, respectively, thanks to this and this . Now I want to display this Filteronly for welcome-filehow I declared it in web.xml.
Let's say I have welcome-fileit index.html, then I need to display Filterfor www.example.com/and www.example.com/index.html, but not for anything else, such as www.example.com/foo/*or www.example.com/*not allowed, I mean NOT anything other than the request welcome-file. I am using the Apache Tomcat 7.0.22 container.

+3
source share
1 answer

Just add them to your web.xml

<filter>
  <filter-name>myFilter</filter-name>
  <filter-class>com.examples.myFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>myFilter</filter-name>
  <url-pattern>/index.html</url-pattern>
</filter-mapping>
+2

All Articles