servlet---web.xml文件配置路径

Servlet的映射路径:

在web.xml文件中:

<servlet-mapping>

   <servlet-name>FirstServlet</servlet-name>//servlet的内部名称

   <url-pattern>/first</url-pattern>//url简称

  </servlet-mapping>

                      url-pattern                    浏览器输入

精确匹配             /first                        http://localhost:8080/day10/first

                           /itcast/demo1          http://localhost:8080/day10/itcast/demo1

模糊匹配             /*                             http://localhost:8080/day10/任意路径

/itcast/*                                               http://localhost:8080/day10/itcast/任意路径

*.后缀名                                              http://localhost:8080/day10/任意路径.do

*.do

*.action

*.html(伪静态)

[注]:

1)url-pattern要么以 / 开头,要么以*开头。  例如,itcast是非法路径。

2)不能同时使用两种模糊匹配,例如 /itcast/*.do是非法路径

3)当有输入的URL有多个servlet同时被匹配的情况下:

4) 精确匹配优先。(长的最像优先被匹配)

5) 以后缀名结尾的模糊url-pattern优先级最低

6)servlet的缺省路径(<url-pattern>/</url-pattern>)是在tomcat服务器内置的一个路径。该路径对应的是一个DefaultServlet(缺省Servlet)。这个缺省的Servlet的作用是用于解析web应用的静态资源文件。(配置文件中存放)

7)先找动态资源,再找静态资源。

猜你喜欢

转载自blog.csdn.net/weixin_40775755/article/details/82423053