Servlet过滤器 - 来自servlet的转发请求是否会转到servlet过滤器? [英] Servlet Filter - forwarded request from a servlet will go to servlet filter or not?

查看:310
本文介绍了Servlet过滤器 - 来自servlet的转发请求是否会转到servlet过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果任何 J2EE 应用程序直接命中servlet,然后servlet将相同的请求转发到某些 .jsp 页面。

If any J2EE application hit servlet directly and then servlet forward the same request to some .jsp page.

request.getRequestDispatcher("Login.jsp").forward(request, response);

我有一个servlet过滤器,下面是url-pattern

And I have a servlet filter with below url-pattern

<filter-mapping>
    <filter-name>some_filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

因此,转发请求是否也会过滤。

So, will that forwarded request comes to filter also or not.

在我的情况下它不会来,这是一个预期的行为。只想了解这一点。

In my case it is not coming, is this a as expected behaviour. Just want to understand this.

推荐答案

如果要为转发请求调用过滤器映射,则必须将其放入web.xml

If you want the filter mapping to be invoked for forward requests, you have to put this in web.xml

自Servlet2.4起支持此支持

This support is there since Servlet2.4

<filter-mapping>
  <filter-name>myfilter</filter-name>
  <url-pattern>/mypath/*</url-pattern>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

调度员支持的值为:


  • 请求:请求直接来自客户端。这由< dispatcher> 元素表示,其值为 REQUEST ,或者
    缺席任何元素< dispatcher> 元素。

  • REQUEST: The request comes directly from the client. This is indicated by a <dispatcher> element with value REQUEST, or by the absence of any <dispatcher> elements.

FORWARD :请求正在在代表与< url-pattern> < servlet-name> 匹配的Web组件的请求调度程序下处理使用 forward()调用。
这由< dispatcher> 元素表示,其值为 FORWARD

FORWARD: The request is being processed under a request dispatcher representing the Web component matching the <url-pattern> or <servlet-name> using a forward() call. This is indicated by a <dispatcher> element with value FORWARD.

INCLUDE :正在请求调度程序处理请求,该请求调度程序表示与< url-pattern>匹配的Web组件< servlet-name> 使用 include()调用。
这由< dispatcher> 元素表示,其值为 INCLUDE

INCLUDE: The request is being processed under a request dispatcher representing the Web component matching the <url-pattern> or <servlet-name> using an include() call. This is indicated by a <dispatcher> element with value INCLUDE.

错误:使用错误处理中指定的错误页面机制处理的请求到与匹配的错误资源< URL模式> 。这由< dispatcher> 元素表示,其值为 ERROR

ERROR: The request that is being processed with the error page mechanism specified in "Error Handling" to an error resource matching the <url-pattern>. This is indicated by a <dispatcher> element with the value ERROR.

ASYNC :正在使用异步处理中指定的异步上下文调度机制使用调度调用将请求处理到Web组件。
这由< dispatcher> 元素表示,其值为 ASYNC

ASYNC: The request is being processed with the async context dispatch mechanism specified in "Asynchronous processing" to a web component using a dispatch call. This is indicated by a <dispatcher> element with the value ASYNC.

这篇关于Servlet过滤器 - 来自servlet的转发请求是否会转到servlet过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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