Java 如何在web.xml中为Tomcat映射欢迎文件的筛选器?
我已经创建了一个Java 如何在web.xml中为Tomcat映射欢迎文件的筛选器?,java,tomcat,mapping,servlet-filters,Java,Tomcat,Mapping,Servlet Filters,我已经创建了一个过滤器来检查带有请求对象的Cookies,并相应地转发请求,这要感谢和提问。.现在我想映射这个过滤器,只映射欢迎文件,正如我在web.xml中声明的那样。 假设我有welcome file作为index.html,那么我必须为www.example.com/和www.example.com/index.html映射过滤器,但不允许为www.example.com/foo/*或www.example.com/*等任何其他对象映射,我指的不是任何东西,除了欢迎文件请求。 我正在使用A
过滤器
来检查带有请求对象的Cookie
s,并相应地转发请求,这要感谢和提问。.现在我想映射这个过滤器
,只映射欢迎文件
,正如我在web.xml
中声明的那样。
假设我有welcome file
作为index.html
,那么我必须为www.example.com/
和www.example.com/index.html
映射过滤器
,但不允许为www.example.com/foo/*
或www.example.com/*
等任何其他对象映射,我指的不是任何东西,除了欢迎文件
请求。
我正在使用ApacheTomcat 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>
我的过滤器
com.examples.myFilter
我的过滤器
/index.html
这对www.example.com
案例有帮助吗?URL模式不清楚contanier将提供什么文件?是的,如果您没有更改context.xml中的主机名。“/”表示应用程序的根目录,将提供index.html,因为您在欢迎文件中提到了同样的内容,它应该位于WebContent文件夹中