分享

让Filter过滤内部转发的请求

 且看且珍惜 2014-05-07
在java web开发中配置过滤器默认都是针对外部的请求进行过滤,而通过
request.getRequestDispatcher("url").forward(request,response)
进行请求转发的则不被过滤,其实要让过滤器实现这个功能,只要在web.xml文件中稍做配置即可。

代码片段(1) [全屏查看所有代码]

1. [代码][XML]代码     跳至 [1] [全屏预览]

01<?xml version="1.0" encoding="UTF-8"?>
02<web-app xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns="http://java./xml/ns/javaee" xmlns:jsp="http://java./xml/ns/javaee/jsp" xmlns:web="http://java./xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java./xml/ns/javaee http://java./xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
03  <display-name>TestFilter</display-name>
04  <welcome-file-list>
05    <welcome-file>index.html</welcome-file>
06    <welcome-file>index.htm</welcome-file>
07    <welcome-file>index.jsp</welcome-file>
08    <welcome-file>default.html</welcome-file>
09    <welcome-file>default.htm</welcome-file>
10    <welcome-file>default.jsp</welcome-file>
11  </welcome-file-list>
12  <filter>
13    <display-name>ActionFilter</display-name>
14    <filter-name>ActionFilter</filter-name>
15    <filter-class>test.web.ActionFilter</filter-class>
16  </filter>
17  <filter-mapping>
18    <filter-name>ActionFilter</filter-name>
19    <url-pattern>*.do</url-pattern>
20    <dispatcher>REQUEST</dispatcher>
21    <dispatcher>FORWARD</dispatcher>
22    <dispatcher>INCLUDE</dispatcher>
23  </filter-mapping>
24</web-app>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多