如何在web.xml中为Tomcat映射welcome-file的过滤器?

时间:2012-04-14 23:37:36

标签: java tomcat mapping servlet-filters

由于thisthis问题,我创建了一个Filter来检查带有请求对象的Cookieforward相应的请求。现在我想将此Filter映射为我在welcome-file中声明的web.xml。{
假设我welcome-fileindex.html,那么我必须为Filterwww.example.com/映射www.example.com/index.html,而不是www.example.com/foo/*等其他任何内容或www.example.com/*是不允许的,我的意思是除welcome-file请求之外的任何内容。 我正在使用Apache Tomcat 7.0.22容器。

1 个答案:

答案 0 :(得分:2)

只需将这些添加到您的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>