在web.xml
檔中的web-app
塊的welcome-file-list
子元素用於定義歡迎檔列表。 它的子元素是welcome-file
,用於定義歡迎檔(即默認打開的頁面)。
歡迎檔是伺服器自動調用的檔,如果不指定任何檔案名。
默認情況下,伺服器按以下順序查找歡迎檔:
web.xml
檔中的welcome-file-list
指定的檔- index.html
- index.html
- index.jsp
如果沒有找到這些檔,伺服器會報告404錯誤。
如果在web.xml
中指定了welcome-file
,並且所有檔index.html
,index.html
和index.jsp
都存在,那麼優先順序將轉到welcome-file
。
如果web.xml
檔中不存在welcome-file-list
項,那麼優先順序到index.html
檔,然後是index.html
,以及最後是index.jsp
檔。
下麵來看看一個定義歡迎檔的web.xml
檔。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>helloworld</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
</web-app>
現在,index.html
,index.jsp
和home.jsp
將是歡迎檔。
如果有歡迎檔,可以按如下所示的方式調用專案:
http://localhost:8888/helloproject
如上所示,我們並沒有在專案名稱(helloproject
)之後指定任何檔案名。上面URL訪問相當於以下三個 -
http://localhost:8888/helloproject/index.html
http://localhost:8888/helloproject/index.jsp
http://localhost:8888/helloproject/home.jsp
上一篇:
War檔
下一篇:
Servlet啟動時加載