引言
我們在創建 Web 項目啟動 Tomcat 會自動打開一個默認 index.jsp 頁面,這個頁面是創建 Web 項目時就自動生成的。那么,如何設置 web 項目打開的這個的默認頁面,改為自己的默認啟動頁面呢?
修改配置 web.xml 文件
在 web.xml 配置文件設置默認頁面
<welcome-file-list>
<welcome-file>login.html</welcome-file>
<welcome-file>login.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
在 tomcat 啟動項目時,就會在項目目錄下面自上而下逐一查找文件,如果找到了如上 6 個中的某一個文件,則以這個文件為 welcom-file,也就是這個項目的默認頁面。
如果我們只需要一個打開默認頁面,那么就只配置一個即可,如下:
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
這時,就可以把項目中自動生成的 index.jsp 頁面刪除了。