1. 程式人生 > >servlet---web.xml檔案配置路徑

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)先找動態資源,再找靜態資源。