如何在web.xml中为Tomcat映射welcome-file的过滤器? [英] How to map a filter for welcome-file in web.xml for Tomcat?
问题描述
我创建了一个过滤器
来检查带有请求对象的 Cookie
和转发
相应的请求感谢这个和这个问题。现在我只想为欢迎文件过滤
code>因为我在 web.xml
中声明了它。
假设我有 welcome-file
as index.html
然后我必须为映射
和过滤器
www.example.com / www.example.com/index.html
但不能用于其他任何内容,例如 www .example.com / foo / *
或 www.example.com / *
是不允许的,我的意思是什么,除了 welcome-file
请求。
我正在使用Apache Tomcat 7.0.22容器。
I have created a Filter
to check the Cookie
s with request object and forward
the request accordingly thanks to this and this question..Now I want to map this Filter
for just the welcome-file
as I have declared it in web.xml
.
Say I have welcome-file
as index.html
then I have to map the Filter
for both www.example.com/
and www.example.com/index.html
but not for anything else such as www.example.com/foo/*
or www.example.com/*
is not allowed, I mean NOT anything except welcome-file
request.
I am using Apache Tomcat 7.0.22 container.
推荐答案
只需将这些添加到您的web.xml
Just add these 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>
这篇关于如何在web.xml中为Tomcat映射welcome-file的过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!