当 Filter 的调度程序为 FORWARD 以及当调度程序为 REQUEST 时,如何可能应用 Filter?
我有一个简单的过滤器:
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>
或者
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
在这两种情况下我都看到输出:(
before
before
after
after
我也尝试使用 INCLUDE
作为调度程序确保一切正常 - 没有包含 INCLUDE
的输出)。
此过滤器之后还有第 3 方过滤器和 servlet,我想知道:他们应该做什么才能使我的过滤器应用于所描述的两种情况?
I have a simple Filter:
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() {
}
}
It's the first filter in web.xml and it has one of these two mappings:
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
or
<filter-mapping>
<filter-name>cookie-test-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
In both cases I see the output:
before
before
after
after
(I've also tried INCLUDE
as dispatcher just to be sure that everything works - there's no output with INCLUDE
).
There're 3rd-party filters and servlets after this filter and I wonder: what should they do to make my filter applied in both described cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将单个
条目与 REQUEST 和 FORWARD 调度程序示例
一起使用希望这能解决问题你遇到的问题。
Try using a single
<filter-mapping>
entry with both REQUEST and FORWARD dispatcherExample
Hope this clears up the issue you were having.