标签:javaee servlet url servlet映射
1、Servlet映射可以多层多样
例子:
<servlet> <servlet-name>HServlet</servlet-name> <servlet-class>com.hunhun.HServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HServlet</servlet-name> <url-pattern>/HServlet</url-pattern> <!-- <url-pattern>/abc.html</url-pattern> --> <!-- <url-pattern>/HServlet/abc</url-pattern> --> </servlet-mapping>2、Servlet可以被映射到多个URL上
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>/FirstServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>/GServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>/HServlet</url-pattern> </servlet-mapping>可通过浏览器url:http://localhost:8080/myweb/FirstServlet|GServlet|HServlet访问FirstServlet
(1)使用 *.扩展名
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>可通过浏览器url:http://localhost:8080/myweb/abc.do访问FirstServlet
(2)使用 / 开始 /* 结束
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FirstServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
(1)相似度高的优先匹配
(2)*.扩展名的匹配方式优先级最低
标签:javaee servlet url servlet映射
原文地址:http://blog.csdn.net/hunhunpanda/article/details/41169973