源码
https://github.com/YouXianMing/Java-Web-Study/tree/master/Servlet-Filter-UrlPattern
Filter顺序以及url-pattern规则
实际匹配情况
http://localhost:8080/Servlet-Filter-UrlPattern/demo
http://localhost:8080/Servlet-Filter-UrlPattern/do
http://localhost:8080/Servlet-Filter-UrlPattern/demo.jsp
http://localhost:8080/Servlet-Filter-UrlPattern/do/demo.jsp
需要注意的点
1. Filter按照配置在web.xml中的先后顺序,每一个Filter都会进行url-pattern的匹配,匹配成功,则会执行对应的Filter方法
2. 1个Filter可以设置多个url-pattern
3. Filter匹配有3种模式
1、精确匹配: /directory/file1.jsp /directory/file2.jsp /directory/file3.jsp 2、目录匹配: /directory/* 3、扩展匹配: *.jsp 注意:下面的不支持: /direcotry/*.jsp
/和/*之间的区别: <url-pattern>/</url-pattern>: 会匹配到/login这样的路径型url,不会匹配到模式为*.jsp这样的后缀型url <url-pattern>/*</url-pattern>:会匹配所有url:路径型的和后缀型的url(包括/login , *.jsp , *.js 和 *.html 等) <url-pattern>/</url-pattern>: 甚至会造成The requested resource () is not available.