Problem: i want to do filter for all webapps.
I created a filter for monitoring requests to the apache tomcat server.
for the sake of example, it’s called MyFilter. i created it in netbeans, which created 2 separated 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 when i execute it from netbeans, it deploys it and sends me to http://localhost:8080/MyFilter
whenever i view a page under /MyFilter/somepath – it runs the filter.
i want the filter to run on all paths, and not only for the webapp
Where do i need to locate the project files? which project files do i need? should i edit conf/web.xml and add the filter? or should i only be in the specific webapp’s web.xml?
EDIT:
i copied the generated .war file into tomcat/webapps
when i start tomcat, it creates a directory (tomcat/webapps/MyFilter/)
i added the filter into tomcat/conf/web.xml. when i start it, it fails to load ://localhost:8080/ but successfully loads (and filters) ://localhost:8080/MyFilter
A filter will by definition only ever run within the web application it is defined in.
You could define it in the
web.xmlin theconf/directory of Tomcat to have it included in all web applications deployed to that Tomcat by default (note that you’d also need to make the filter class available to all web applications, probably by putting it in thelib/directory of Tomcat).Alternatively, you can implement a Tomcat Valve, which is conceptually similar to a filter, but can be installed on an Engine, Host or Context in Tomcat.