在java web开发中配置过滤器默认都是针对外部的请求进行过滤,而通过
request.getRequestDispatcher("url").forward(request,response)
进行请求转发的则不被过滤,其实要让过滤器实现这个功能,只要在web.xml文件中稍做配置即可。
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 > |
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 > |
13 | < display-name >ActionFilter</ display-name > |
14 | < filter-name >ActionFilter</ filter-name > |
15 | < filter-class >test.web.ActionFilter</ filter-class > |
18 | < filter-name >ActionFilter</ filter-name > |
19 | < url-pattern >*.do</ url-pattern > |
20 | < dispatcher >REQUEST</ dispatcher > |
21 | < dispatcher >FORWARD</ dispatcher > |
22 | < dispatcher >INCLUDE</ dispatcher > |
|