web.xml 中的 <url-pattern>
是 <servlet-mapping>
或 <filter-mapping>
下的子标签。web
url :http://localhost:8080/project/index 的组成:
http://localhost:8080 服务器地址。以后的为 RequestURI。
/project ServletConext的上下文地址,ServletContext Path。
/index Servlet的地址,Servlet Path,这部分是须要与<url-pattern>匹配的内容。服务器
写法,只有如下四种写法:app
/
开始,后面是具体路径,好比 /index.do
。/
开始,以 /*
结束,好比 /index/*, /*
。*.
开始,以 扩展名 结束,好比 *.do
。/
。映射规则:url
精确路径。code
<url-pattern>/index</url-pattern> 匹配: http://localhost:8080/project/index http://localhost:8080/project/index?name=admin
最长路径。xml
<url-pattern>/index/a/*</url-pattern> 匹配: http://localhost:8080/project/index/a/action 该URL,若是没有第一个 url-pattern ,则可匹配: <url-pattern>/index/*</url-pattern>
扩展名。get
<url-pattern>*.do</url-pattern> 匹配: http://localhost:8080/project/index/a.do
注意事项:servlet
<servlet>
找到第一个,就中止以后的匹配; <filter>
会根据 <filter-mapping>
定义顺序一直向下走。