温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

tomcat如何修改默认页

发布时间:2026-08-28 04:33:22 来源:亿速云 阅读:117 作者:小樊 栏目:系统运维

在 Apache Tomcat 中修改“默认页”(即访问 http://localhost:8080/ 时看到的页面),常见有 3 种方式,按使用场景说明如下:


一、修改 Tomcat 自带默认页(不推荐长期使用)

Tomcat 的默认欢迎页由 web.xml 控制。

1️⃣ 找到 web.xml

路径一般为:

$TOMCAT_HOME/conf/web.xml

2️⃣ 找到 <welcome-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>

3️⃣ 修改为你自己的页面

例如:

<welcome-file-list>
    <welcome-file>myindex.html</welcome-file>
</welcome-file-list>

⚠️ 注意:

  • 这是 全局配置,会影响所有应用
  • 不推荐在生产环境使用

二、修改某个 Web 应用的默认页(✅ 推荐)

1️⃣ 在你的项目中配置 web.xml

路径:

WEB-INF/web.xml

添加或修改:

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

访问:

http://localhost:8080/你的项目名/

会自动找 login.html


三、修改 ROOT 应用(访问 http://localhost:8080/)

Tomcat 中 ROOT 应用 对应 /

方式 1:替换 ROOT 内容(最常用 ✅)

  1. 进入:
$TOMCAT_HOME/webapps/ROOT
  1. 删除或备份原文件
rm -rf *
  1. 放入你的页面,例如:
index.html

访问:

http://localhost:8080/

方式 2:把自己的项目设为 ROOT

方法一:修改 server.xml(不推荐)

<Context path="" docBase="/path/to/your/app" />

方法二(✅ 推荐):使用 ROOT.war

  1. 将你的项目打包成:
ROOT.war
  1. 放到:
$TOMCAT_HOME/webapps/
  1. 重启 Tomcat

四、常见问题

❓ 修改后不生效?

  • 是否重启 Tomcat
  • 浏览器是否缓存(Ctrl + F5)
  • web.xml 是否配置在正确位置

❓ 想直接跳转到某个 Servlet?

<welcome-file-list>
    <welcome-file>index</welcome-file>
</welcome-file-list>

并配置:

<servlet-mapping>
    <servlet-name>IndexServlet</servlet-name>
    <url-pattern>/index</url-pattern>
</servlet-mapping>

总结(推荐做法)

场景 推荐方式
修改某个项目默认页 项目 web.xml
修改 localhost:8080/ 替换 webapps/ROOT
生产环境 使用 ROOT.war

如果你愿意,可以告诉我:

  • ✅ Tomcat 版本
  • ✅ 是否使用 Spring Boot
  • ✅ 是改 / 还是某个项目

我可以给你更精确的配置示例。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手