在 Apache Tomcat 中修改“默认页”(即访问 http://localhost:8080/ 时看到的页面),常见有 3 种方式,按使用场景说明如下:
Tomcat 的默认欢迎页由 web.xml 控制。
web.xml路径一般为:
$TOMCAT_HOME/conf/web.xml
<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>
例如:
<welcome-file-list>
<welcome-file>myindex.html</welcome-file>
</welcome-file-list>
⚠️ 注意:
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
http://localhost:8080/)Tomcat 中 ROOT 应用 对应 /
$TOMCAT_HOME/webapps/ROOT
rm -rf *
index.html
访问:
http://localhost:8080/
server.xml(不推荐)<Context path="" docBase="/path/to/your/app" />
ROOT.war
$TOMCAT_HOME/webapps/
web.xml 是否配置在正确位置<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 |
如果你愿意,可以告诉我:
/ 还是某个项目我可以给你更精确的配置示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。