<filter-mapping>--<dispatcher>
2015-11-01 21:29
155 查看
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..
例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..
相关文章推荐
- Android 日志打印工具类 可显示打印所在的方法和行号
- cocos2d-x 3.x取消dumpCachedTextureInfo代之以getCachedTextureInfo
- cocos2d-x 3.x取消dumpCachedTextureInfo代之以getCachedTextureInfo
- Android 实现一个立方体旋转效果
- Android 检测键盘是否显示及隐藏键盘
- Android中Intent传递对象的两种方法------Serializable传值和Parcelable传值
- Android GPS GPSBasics project hacking
- 如何解决Android studio已分享到github的项目但是git->commit directory提交不上去
- android 73 下载图片
- 零基础ios开发(八 正向和反向传值)
- Android,Java延迟两秒执行
- 【Android】修改App字体的三种方法.md
- Android之ListView的优化
- Git/Framework静态库介绍:创建和使用
- android 实现自动换行的流布局
- Git/.a静态库的介绍:创建和使用
- 如何开发一款优秀的APP(侧重实践层面)
- iOS之OC基础类和对象
- 视频框架 Vitamio 使用教程+部分心得 (四) 滑动控制声音和亮度+android 4.4.X 以上时全屏播放
- Unity3d之UGUI- Image拦截Button响应事件