filter(二) filter中<url-pattern>的匹配规则(转)

下面的代码摘自tomcat源码,用来匹配<filter-mapping>中的<url-pattern>,相信比文字更容易理解:
java 代码
 
  1. /** 
  2.      * Return <code>true</code> if the context-relative request path 
  3.      * matches the requirements of the specified filter mapping; 
  4.      * otherwise, return <code>null</code>. 
  5.      * 
  6.      * @param filterMap Filter mapping being checked 
  7.      * @param requestPath Context-relative request path of this request 
  8.      */  
  9.     private boolean matchFiltersURL(FilterMap filterMap, String requestPath) {  
  10.   
  11.         if (requestPath == null)  
  12.             return (false);  
  13.   
  14.         // Match on context relative request path  
  15.         String testPath = filterMap.getURLPattern();  
  16.         if (testPath == null)  
  17.             return (false);  
  18.   
  19.         // Case 1 - Exact Match  
  20.         if (testPath.equals(requestPath))  
  21.             return (true);  
  22.   
  23.         // Case 2 - Path Match ("/.../*")  
  24.         if (testPath.equals("/*"))  
  25.             return (true);  
  26.         if (testPath.endsWith("/*")) {  
  27.             if (testPath.regionMatches(0, requestPath, 0,   
  28.                                        testPath.length() - 2)) {  
  29.                 if (requestPath.length() == (testPath.length() - 2)) {  
  30.                     return (true);  
  31.                 } else if ('/' == requestPath.charAt(testPath.length() - 2)) {  
  32.                     return (true);  
  33.                 }  
  34.             }  
  35.             return (false);  
  36.         }  
  37.   
  38.         // Case 3 - Extension Match  
  39.         if (testPath.startsWith("*.")) {  
  40.             int slash = requestPath.lastIndexOf('/');  
  41.             int period = requestPath.lastIndexOf('.');  
  42.             if ((slash >= 0) && (period > slash)   
  43.                 && (period != requestPath.length() - 1)  
  44.                 && ((requestPath.length() - period)   
  45.                     == (testPath.length() - 1))) {  
  46.                 return (testPath.regionMatches(2, requestPath, period + 1,  
  47.                                                testPath.length() - 2));  
  48.             }  
  49.         }  
  50.   
  51.         // Case 4 - "Default" Match  
  52.         return (false); // NOTE - Not relevant for selecting filters  
  53.   
  54.     }  
<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://java.sun.com/xml/ns/j2ee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"--> <!-- version="2.4">--> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5.xsd" version="5.0"> <display-name>howie2</display-name> <filter> <filter-name>hmvc</filter-name> <filter-class>com.howie.hmvc.DispatcherFilter</filter-class> </filter> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jhtml</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.aj</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.ar</url-pattern> </filter-mapping> <jsp-config> <taglib> <taglib-uri>asy</taglib-uri> <taglib-location>/WEB-INF/anshuyun.tld</taglib-location> </taglib> </jsp-config> <error-page> <error-code>404</error-code> <location>/error/404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/500.jsp</location> </error-page> <session-config> <session-timeout>20</session-timeout> <!-- <cookie-config> <secure>true</secure> </cookie-config> --> </session-config> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD</http-method> <http-method>OPTIONS</http-method> <http-method>TRACE</http-method> </web-resource-collection> <au
03-20
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>web application framework</display-name> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/waf</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <session-config> <session-timeout>60</session-timeout> <cookie-config><name>JSESSIONID</name></cookie-config> </session-config> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring_context.xml ,classpath:quartz_context.xml ,classpath:spring_context_misc.xml ,classpath:bpms_context.xml, classpath:process_group.xml </param-value> </context-param> <listener> <listener-class>cn.ccccltd.waf.listener.SessionListener</listener-class> </listener> <listener> <listener-class>cn.ccccltd.waf.listener.CacheFileEvent</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class> </listener> <listener> <listener-class>cn.ccccltd.bpms.BpmsInitializer</listener-class> </listener> <listener> <listener-class>cn.ccccltd.bpms.ou.listener.BpmsSessionListener</listener-class> </listener> <filter> <filter-name>SigninFilter</filter-name> <filter-class>cn.ccccltd.waf.SigninFilter</filter-class> <init-param> <param-name>signinUrlPattern</param-name> <param-value>bo,dhtml,dhtm,shtml,shtm</param-value> </init-param> </filter> <filter-mapping> <filter-name>SigninFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ****************************************************************************** --> <filter> <filter-name>xssFilter</filter-name> <filter-class>cn.ccccltd.waf.filter.XssFilter</filter-class> </filter> <filter-mapping> <filter-name>xssFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>SSOLoginFilter</filter-name> <filter-class>cn.ccccltd.waf.sso.controller.SSORequestController</filter-class> </filter> <filter-mapping> <filter-name>SSOLoginFilter</filter-name> <url-pattern>*.bo</url-pattern> </filter-mapping> <!--<filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping>--> <servlet> <servlet-name>appDispatcher</servlet-name> <servlet-class>cn.ccccltd.waf.AppDispatcher</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring_dispatcher_context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Spring MVC 请求映射 --> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.bo</url-pattern> </servlet-mapping> <servlet> <servlet-name>appLoader</servlet-name> <servlet-class>cn.ccccltd.waf.AppLoader</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>monitorLoader</servlet-name> <servlet-class>cn.ccccltd.waf.MonitorLoader</servlet-class> <load-on-startup>30</load-on-startup> </servlet> <servlet> <servlet-name>fileUpload</servlet-name> <servlet-class>cn.ccccltd.waf.tool.FileUpload</servlet-class> <load-on-startup>97</load-on-startup> </servlet> <servlet> <servlet-name>randomCode</servlet-name> <servlet-class>cn.ccccltd.waf.tool.RandomCode</servlet-class> <load-on-startup>99</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.dhtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.dhtm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.shtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.shtm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>fileUpload</servlet-name> <url-pattern>/waf/tool/fileUpload</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>randomCode</servlet-name> <url-pattern>/waf/tool/randomCode</url-pattern> </servlet-mapping> <servlet> <servlet-name>FileUploadServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.FileUploadServlet</servlet-class> <init-param> <param-name>fileSizeLimit</param-name> <param-value>2000</param-value> </init-param> </servlet> <servlet> <servlet-name>DeleteFileServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.DeleteFileServlet</servlet-class> </servlet> <servlet> <servlet-name>FileDownloadServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.FileDownloadServlet</servlet-class> </servlet> <!-- 帆软报表 --> <!-- <servlet> <servlet-name>ReportServer</servlet-name> <servlet-class>com.fr.web.ReportServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ReportServer</servlet-name> <url-pattern>/ReportServer</url-pattern> </servlet-mapping> --> <servlet-mapping> <servlet-name>FileDownloadServlet</servlet-name> <url-pattern>/FileDownloadServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FileUploadServlet</servlet-name> <url-pattern>/FileUploadServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>DeleteFileServlet</servlet-name> <url-pattern>/DeleteFileServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- error-page START --> <!-- 400 --> <error-page> <error-code>400</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 403 --> <error-page> <error-code>403</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 404 --> <error-page> <error-code>404</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 500 --> <error-page> <error-code>500</error-code> <location>/errorPage.jsp</location> </error-page> <!-- error-page END --> </web-app>那你给我修改一下文件都在项目之中。
最新发布
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值