如何在web.xml中为Tomcat映射welcome-file的过滤器? [英] How to map a filter for welcome-file in web.xml for Tomcat?

查看:194
本文介绍了如何在web.xml中为Tomcat映射welcome-file的过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个过滤器来检查带有请求对象的 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 Cookies 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屋!

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