设置Tomcat默认主页(指定欢迎页)的两种方法

来源:岁月联盟 编辑:zhuzhu 时间:2009-04-30
方法一:(适合对服务器中单个站点的设置)
(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>