我创建了一个 Filter
检查 Cookie
s 带有请求对象和 forward
相应的请求感谢this和 this问题..现在我想映射这个 Filter
仅适用于 welcome-file
正如我在 web.xml
中声明的那样.
假设我有 welcome-file
作为index.html
然后我必须映射 Filter
对于www.example.com/
和 www.example.com/index.html
但不适用于其他任何东西,例如 www.example.com/foo/*
或 www.example.com/*
是不允许的,我的意思是除了welcome-file
之外什么都没有要求。
我正在使用 Apache Tomcat 7.0.22 容器。
最佳答案
只需将这些添加到您的 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>
关于java - 如何在 Tomcat 的 web.xml 中为欢迎文件映射过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10158280/