修改 Tomcat 默认首页

Tomcat 启动默认 webapp/ROOT 目录下的 index.jsp 文件,下面我们通过修改配置文件来指定 Tomcat 的默认启动首页。

1、在 webapp 目录下创建 myroot 文件夹,由于存放我们的首页文件,可以把我们写好的 index.html 文件放到里面。

2、修改 conf 目录下的 server.xml 文件,找到 <Host> 标签,然后添加代码如下:

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

        <!-- 重定向首页位置 -->
        <Context path="" docBase="myroot" debug="0" reloadable="true"/>

这里使用 <Context> 标签来指定首页位置,docBase 的值为我们刚才创建的首页目录。

3、修改 conf/web.xml 文件,找到 <welcom-file-list> 标签,里面添加首页的文件名,默认已经带有了几种首页文件:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

可以往里面添加自己指定的首页名称,一般我们使用 index.html 就可以了。修改完后,重启 Tomcat,就可以看到我们指定的首页了。

  • 7
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值