zoukankan      html  css  js  c++  java
  • <filter-mapping>--<dispatcher>

    2.4版本的servlet规范在部属描述符中新增加了一个<dispatcher>元素,这个元素有四个可能的值:即REQUEST,FORWARD,INCLUDE和ERROR,可以在一个<filter-mapping>元素中加入任意数目的<dispatcher>,使得filter将会作用于直接从客户端过来的request,通过forward过来的request,通过include过来的request和通过<error-page>过来的request。如果没有指定任何< dispatcher >元素,默认值是REQUEST。可以通过下面几个例子来辅助理解。
    例1:
    <filter-mapping>
    <filter-name>Logging Filter</filter-name>
    <url-pattern>/products/*</url-pattern>
    </filter-mapping>
    这种情况下,过滤器将会作用于直接从客户端发过来的以/products/…开始的请求。因为这里没有制定任何的< dispatcher >元素,默认值是REQUEST。

    例2:
    <filter-mapping>
            <filter-name>Logging Filter</filter-name>
            <servlet-name>ProductServlet</servlet-name>
            <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    这种情况下,如果请求是通过request dispatcher的include方法传递过来的对ProductServlet的请求,则要经过这个过滤器的过滤。其它的诸如从客户端直接过来的对ProductServlet的请求等都不需要经过这个过滤器。
    指定filter的匹配方式有两种方法:直接指定url-pattern和指定servlet,后者相当于把指定的servlet对应的url-pattern作为filter的匹配模式
    filter的路径匹配和servlet是一样的,都遵循servlet规范中《SRV.11.2 Specification of Mappings》一节的说明

    例3:
    <filter-mapping>
            <filter-name>Logging Filter</filter-name>
            <url-pattern>/products/*</url-pattern>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    在这种情况下,如果请求是以/products/…开头的,并且是通过request dispatcher的forward方法传递过来或者直接从客户端传递过来的,则必须经过这个过滤器。
    The dispatcher has four legal values: FORWARD, REQUEST, INCLUDE,and ERROR. A value of FORWARD means the Filter will be appliedunder RequestDispatcher.forward() calls. A value of REQUESTmeans 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..

  • 相关阅读:
    《一网打尽》:贝佐斯粗暴刻薄,商业战略上的几次成功决策造了今天的亚马逊
    《信息简史》:计算机史前史
    《孵化Twitter》:Twitter创始人勾心斗角史,细节披露程度令人吃惊
    《走出电商困局》:与《我看电商》有不少重复,反复强调电商要重视成本
    转贴健康资讯:感冒了,是因为着凉吗?
    《众病之王》:人类探索癌症诊断治疗的历史
    转发健康资讯:寒冷会导致关节炎吗?
    《淘宝十年产品事》淘宝产品演进史及作者的思考
    [React] How to use a setState Updater Function with a Reducer Pattern
    [HTML5] Text Alternatives
  • 原文地址:https://www.cnblogs.com/curry1234/p/4928726.html
Copyright © 2011-2022 走看看