且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tomcat的设置2——设置虚拟子目录和欢迎页

更新时间:2022-09-27 15:10:47

<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/testProject1" docBase="E:\apache-tomcat-test_project" />
<Context path="/testProject2" docBase="E:\apache-tomcat-test_project\tomatTest" />
</Host>

E:\apache-tomcat-test_project中有testIndex.html
通过http://127.0.0.1:8080/testProject1/testIndex.html可以访问

E:\apache-tomcat-test_project\tomatTest中有testIndex.html
通过http://127.0.0.1:8080/testProject2/testIndex.html可以访问

可以新增设置WEB-INF文件夹和其中的web.xml设置欢迎页:
在tomatTest新增WEB-INF文件夹,在WEB-INF文件夹中添加文件web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<welcome-file-list>
<welcome-file>testIndex.html</welcome-file>
</welcome-file-list>
</web-app>

这样访问http://127.0.0.1:8080/testProject2就可以访问testIndex.html页面了。


当然在基准目录webapps放一个项目文件夹就可以直接访问,通过MyEclipse开发部署经常会这么做,这是基准目录带来的方便。

本文转自IT徐胖子的专栏博客51CTO博客,原文链接http://blog.51cto.com/woshixy/1355130如需转载请自行联系原作者


woshixuye111