有人可以告诉我,DispatcherType正在做什么?
似乎是一个重要的配置.
通过指向诸如ServletContextHandler#addFilter之类的东西,类的使用也没有帮助我,这是用明智的词语"记录"的:convenience method to add a filter.
一般来说,任何机会都可以"理解" 未记录的 Jetty API而无需代码示例 - 搜索 - 乐趣或尝试 - 失败和奇迹?
Asa*_*bal 14
这也是web.xml中的一个设置; 并且可能已经存在了相当长的一段时间.
http://download.oracle.com/docs/cd/B32110_01/web.1013/b28959/filters.htm#BCFIEDGB
本节提供了一些示例配置,以使过滤器作用于前进或包含目标.我们从过滤器声明开始,然后是备用过滤器映射配置:
<filter>
<filter-name>myfilter</filter-name>
<filter-class>mypackage.MyFilter</filter-class>
</filter>
Run Code Online (Sandbox Code Playgroud)
要执行MyFilter以过滤名为includedservlet的包含目标,请执行以下操作:
<filter-mapping>
<filter-name>myfilter</filter-name>
<servlet-name>includedservlet</servlet-name>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
请注意,include()调用可以来自应用程序中的任何servlet(或其他资源).另请注意,除非您有另一个值为REQUEST的元素,否则MyFilter不会执行includedservlet的直接请求.
要执行MyFilter以过滤通过URL模式"/ mypath /"直接请求的任何servlet,或执行它以过滤通过以"/ mypath /"开头的URL模式调用的任何前向目标:
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>/mypath/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
~~~~~~~~~~~~~~~~~~~~~~
此外,默认为Request; 阅读下面的applyTo(...)方法:
Bog*_*mac 10
添加到Asad的答案,调度程序不是特定于Jetty的,它是2.2版之前的servlet规范的一部分.以下是来自web-app_2_5.xsd的调度程序值的官方说明:
<xsd:complexType name="dispatcherType">
<xsd:annotation>
<xsd:documentation>
The dispatcher has four legal values: FORWARD, REQUEST, INCLUDE,
and ERROR. A value of FORWARD means the Filter will be applied
under RequestDispatcher.forward() calls. A value of REQUEST
means the Filter will be applied under ordinary client calls to
the path or servlet. A value of INCLUDE means the Filter will be
applied under RequestDispatcher.include() calls. A value of
ERROR means the Filter will be applied under the error page
mechanism. The absence of any dispatcher elements in a
filter-mapping indicates a default of applying filters only under
ordinary client calls to the path or servlet.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="javaee:string">
<xsd:enumeration value="FORWARD"/>
<xsd:enumeration value="INCLUDE"/>
<xsd:enumeration value="REQUEST"/>
<xsd:enumeration value="ERROR"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)