所有webapps的tomcat过滤器 [英] tomcat filter for all webapps

查看:122
本文介绍了所有webapps的tomcat过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我想对所有webapps进行过滤。



我创建了一个过滤器,用于监控对apache tomcat服务器的请求。



为了举例,它被称为MyFilter。我在netbeans中创建了它,创建了2个独立的目录:

  webpages  - 包含:
META-INF
WEB-INF
index.jsp(我为查看受监控数据而创建的文件)

源包
my.package / MyFilter

同样当我从netbeans执行它时,它会部署它并将我发送到 http:// localhost:8080 / MyFilter



每当我在/ MyFilter / somepath下查看页面时 - 它运行过滤器。



我希望过滤器在所有路径上运行,而不仅仅是针对webapp



哪里做我需要找到项目文件?我需要哪些项目文件?我应该编辑conf / web.xml并添加过滤器吗?或者我应该只在特定的webapp的web.xml中?



编辑:



<我将生成的.war文件复制到tomcat / webapps



当我启动tomcat时,它创建了一个目录(tomcat / webapps / MyFilter /)



我将过滤器添加到tomcat / conf / web.xml中。当我启动它时,它无法加载:// localhost:8080 /但成功加载(和过滤器):// localhost:8080 / MyFilter

解决方案

根据定义的过滤器只能在定义的Web应用程序中运行。



您可以在Tomcat的 conf / 目录中的 web.xml ,使其包含在部署到该Tomcat的所有Web应用程序中default(请注意,您还需要将过滤器类用于所有Web应用程序,可能将其放在Tomcat的 lib / 目录中。)



或者,您可以实施 Tomcat Valve ,在概念上类似于过滤器,但可以安装在Tomcat中的引擎,主机或上下文中。


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.xml in the conf/ 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 the lib/ 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.

这篇关于所有webapps的tomcat过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆