- Sphinx_yong
- 等级: 初级会员
- 性别:
- 文章: 52
- 积分: 30
- 来自: 深圳
|
下面的代码摘自tomcat源码,用来匹配<filter-mapping>中的<url-pattern>,相信比文字更容易理解:
java 代码
-
-
-
-
-
-
-
-
- private boolean matchFiltersURL(FilterMap filterMap, String requestPath) {
-
- if (requestPath == null)
- return (false);
-
-
- String testPath = filterMap.getURLPattern();
- if (testPath == null)
- return (false);
-
-
- if (testPath.equals(requestPath))
- return (true);
-
-
- if (testPath.equals("/*"))
- return (true);
- if (testPath.endsWith("/*")) {
- if (testPath.regionMatches(0, requestPath, 0,
- testPath.length() - 2)) {
- if (requestPath.length() == (testPath.length() - 2)) {
- return (true);
- } else if ('/' == requestPath.charAt(testPath.length() - 2)) {
- return (true);
- }
- }
- return (false);
- }
-
-
- if (testPath.startsWith("*.")) {
- int slash = requestPath.lastIndexOf('/');
- int period = requestPath.lastIndexOf('.');
- if ((slash >= 0) && (period > slash)
- && (period != requestPath.length() - 1)
- && ((requestPath.length() - period)
- == (testPath.length() - 1))) {
- return (testPath.regionMatches(2, requestPath, period + 1,
- testPath.length() - 2));
- }
- }
-
-
- return (false);
-
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|