【发布时间】:2011-04-09 05:59:51
【问题描述】:
你能帮忙检查一下为什么 doFilter 没有被调用
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<filter>
<filter-name>roseFilter</filter-name>
<filter-class>net.paoding.rose.RoseFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>roseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
</web-app>
类签名:
import org.springframework.web.filter.GenericFilterBean;
public class RoseFilter extends GenericFilterBean {
调用http://localhost:8080/hello/world时返回404,我将断点设置在 doFilter,好像doFilter没有被调用?(我试过tomcat 6.0.18, 6.0.29, jdk1.6)
【问题讨论】:
-
/hello/world是否解析为您的服务器的资源?如果没有,则没有理由启动过滤器链。 -
我很确定我自己以前也遇到过这种情况,
/*模式不起作用。我想我从来没有解决过它。 -
@rsp:资源不一定是物理现有资源。无论如何都会调用映射在
/*上的过滤器(和 servlet)。它可能即充当前端控制器。 -
@BalusC,当路径没有匹配到servlet或其他非过滤器资源时,过滤器链是否启动? web.xml 只指定了一个监听器和一个过滤器,没有别的。
-
@rsp:当然可以。否则像 Spring (MVC) 这样的基于过滤器 (MVC) 的框架将永远无法工作。
标签: java servlets servlet-filters