Tomcat filter for all webapps

Problem: I want to make a filter for all webapps.

I created a filter to monitor requests to the Tomcat Apache server.

for example, it is called MyFilter. I created it in netbeans, which created 2 shared directories:

webpages - contains: META-INF WEB-INF index.jsp (a file which i created for viewing monitored data) source packages my.package/MyFilter 

in the same case, when I execute it from netbeans, it expands it and sends to http: // localhost: 8080 / MyFilter

whenever I look at a page under / MyFilter / somepath - it starts a filter.

I want the filter to work on all paths, not just webapp

Where do I need to find project files? What project files do I need? should i edit conf / web.xml and add a filter? or should I only be in a specific webapp web.xml?

EDIT:

i copied the generated .war file to tomcat / webapps

when i start tomcat it creates a directory (tomcat / webapps / MyFilter /)

I added a filter to tomcat / conf / web.xml. when I run it, it cannot load: // localhost: 8080 /, but successfully loads (and filters): // localhost: 8080 / MyFilter

+4
source share
1 answer

The filter by definition will only be executed in the web application in which it is defined.

You can define it in web.xml in the conf/ Tomcat directory to include it in all web applications deployed to Tomcat by default (note that you also need to make the filter class available to all web applications, possibly by placing it to the lib/ Tomcat directory).

Alternatively, you can implement Tomcat Valve , which is conceptually similar to a filter, but can be installed on Engine, Host or Context in Tomcat.

+9
source

All Articles