打开tomcat主目录在conf文件夹下面到开server.xml文件找到如下的Host标签
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- 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 -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
在Host标签之间加入
<Context path="/test" docBase="e:\myWeb">
</Context>
最终文件:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- 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 -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
<Context path="/test" docBase="e:\myWeb">
</Context>
</Host>
打开conf文件夹下的web.xml文件,找到如下的部分:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
注意如果你的listings参数的值不是true,应该改为true,否则在浏览器中输入http://localhost:8080/test/时会出现请求的资源不存在
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
在电脑E盘新建一个文件夹命名为myWeb,它就是存放你的web应用的主目录,相当于之前tomcat主目录下面的webapps目录,它被映射为虚拟目录test
所以在访问E:/myWeb下的web应用项目时,在浏览器地址栏中输入的地址就应该是http://localhost:8080/test/
建好myWeb文件夹以后,你的tomcat虚拟目录基本就算配置完成了,此时再重新启动tomcat服务器
打开浏览器输入http://localhost:8080/test/测试一下,如果你的myWeb文件夹中没有任何Web项目时应该呈现出如下的样子
我给E:/myWeb下面一个项目放了FirstApp,重新启动tomcat后,访问http://localhost:8080/test