方法一:(適合對服務器中單個站點的設置)
(d:/demo/為站點根目錄)
在Tomcat中,默認主頁為:index.html,index.htm,index.jsp
如果需要使用其他頁面作為默認主頁,需要配置WEB-INF文件夾下的web.xml文件:
如上例中:
在D:/demo/WEB-INF/文件夾中建立文件web.xml:
內容如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”2.4″
xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>
方法二:(以下設置將應用于該服務器下所有的站點)推薦使用
打開文件conf/web.xml,找到這段代碼:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在中間加入你想要的文件名即可。
如:我想讓hello.jsp成為默認首頁,我將上面那段代碼改成:
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
新聞熱點
疑難解答