JAVA全系列 教程
3762个小节阅读:7090.9k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
精确匹配
精确匹配是指
xxxxxxxxxx
<servlet-mapping>
<servlet-name>demoServlet</servlet-name>
<url-pattern>/demo.do</url-pattern>
</servlet-mapping>
http://localhost:8888/demo/demo.do 匹配
http://localhost:8888/demo/suibian/demo.do 不匹配
扩展名匹配
在
xxxxxxxxxx
<servlet-mapping>
<servlet-name>demoServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
http://localhost:8888/demo/abc.do 匹配
http://localhost:8888/demo/suibian/haha.do 匹配
http://localhost:8888/demo/abc 不匹配
路径匹配
根据请求路径进行匹配,在请求中只要包含该路径都匹配。“*”表示任意路径以及子路径。
xxxxxxxxxx
<servlet-mapping>
<servlet-name>demoServlet</servlet-name>
<url-pattern>/suibian/*</url-pattern>
</servlet-mapping>
http://localhost:8888/demo/suibian/haha.do 匹配
http://localhost:8888/demo/suibian/hehe/haha.do 匹配
http://localhost:8888/demo/hehe/heihei.do 不匹配
任意匹配
匹配“/”。匹配所有但不包含JSP页面。
xxxxxxxxxx
<url-pattern>/</url-pattern>
http://localhost:8888/demo/suibian.do 匹配
http://localhost:8888/demo/addUser.html 匹配
http://localhost:8888/demo/css/view.css 匹配
http://localhost:8888/demo/addUser.jsp 不匹配
http://localhost:8888/demo/user/addUser.jsp 不匹配
匹配所有
xxxxxxxxxx
<url-pattern>/*</url-pattern>
http://localhost:8888/demo/suibian.do 匹配
http://localhost:8888/demo/addUser.html 匹配
http://localhost:8888/demo/suibian/suibian.do 匹配
当一个url与多个Servlet的匹配规则可以匹配时,则按照 “ 精确路径 > 最长路径 > 扩展名”这样的优先级匹配到对应的Servlet。
Servlet1 映射到 /abc/*
Servlet2 映射到 /*
Servlet3 映射到 /abc
Servlet4 映射到 *.do
当请求URL为“/abc/a.html”,“/abc/* ”和“/* ”都匹配,Servlet引擎将调用Servlet1。
当请求URL为“/abc”时,“/abc/* ”和“/abc”都匹配,Servlet引擎将调用Servlet3。
当请求URL为“/abc/a.do”时,“/abc/* ”和“ *.do”都匹配,Servlet引擎将调用Servlet1。
当请求URL为“/a.do”时,“/* ”和“*.do”都匹配,Servlet引擎将调用Servlet2。
当请求URL为“/xxx/yyy/a.do”时,“/* ”和“*.do”都匹配,Servlet引擎将调用Servlet2。