【发布时间】:2013-07-11 21:42:54
【问题描述】:
我正在制作一个小型网络应用程序(这可能被认为是一项单任务)。我的工具是java7、tomcat7.0.40。
我有一个过滤器,叫做 FlowFilter。下面是web.xml中FlowFilter的定义和映射:
<filter>
<filter-name>FlowFilter</filter-name>
<filter-class>path.to.filter.FlowFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>FlowFilter</filter-name>
<url-pattern></url-pattern>
<url-pattern>*.flow</url-pattern>
<url-pattern>*.request</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
我的 webapp 根目录位于:http://[host]/mywebapp。
我还有一个通过 web.xml 配置的欢迎文件:
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
从映射上看,我需要 FlowFilter 正好在以下 3 种情况下执行:
- 当请求以“.flow”结束时
- 当请求以“.request”结束时
- 当我访问 http://[host]/mywebapp(“”映射)时。
问题是在第三种情况下永远不会调用 FlowFilter。
正如我在 servlet-3 规范 12.2 和 6.2.4 中所读到的,url-pattern 规则适用于过滤器。
但是当我调试 Tomcat 的 ApplicationFilterFactory.matchFiltersURL 时,过滤器的 url 模式永远不会与“”映射匹配。
问题是:只是Tomcat还没有实现这样的功能,还是我误读了规范或者我以错误的方式映射过滤器,以及为什么。
谢谢。
【问题讨论】:
标签: java jsp filter servlet-3.0