Java 当它的分派器是转发的,以及当分派器是请求的时,如何应用筛选器?
我有一个简单的过滤器:Java 当它的分派器是转发的,以及当分派器是请求的时,如何应用筛选器?,java,servlets,servlet-filters,dispatcher,Java,Servlets,Servlet Filters,Dispatcher,我有一个简单的过滤器: public class TestFilter implements Filter { public void init(FilterConfig filterConfig) throws ServletException { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException
public class TestFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("before");
chain.doFilter(request, response);
System.out.println("after");
}
public void destroy() {
}
}
它是web.xml中的第一个过滤器,具有以下两个映射之一:
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
(我还尝试了INCLUDE
作为调度器,只是为了确保一切正常-没有INCLUDE
的输出)
在这个过滤器之后有第三方过滤器和servlet,我想知道:他们应该怎么做才能使我的过滤器在这两种情况下都适用?尝试使用一个
条目,同时使用请求和转发调度程序
示例
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
cookie测试过滤器
/*
要求
向前地
希望这能解决您遇到的问题。您正在使用哪个应用服务器,包括其版本?在您的web.xml中,
web-app
元素的version
属性的值是多少?@kschneid:Apache Tomcat 6.0.30,web-app version=“2.4”您确定web.xml
中只有一个过滤器映射吗?当您有相同筛选器的两个映射时,可能会发生这种情况。
before
before
after
after
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>