1.为什么要使用 tomcat虚拟路径?
1.1众所众知tomcat的目录结构如下图所示
1.2现在我们有需求就是d盘下的myJsp2项目不放在webapps下但是达到可以使用浏览器访问myJsp2这个web项目
2.如何配置虚拟项目?
2.1从上面的图片我们知道config是tomcat的配置目录,点开该目录,找到server.xml
2.2在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 "%r" %s %b" />
<Context docBase = "D:\myJsp2" path="/myJsp2"/>
</Host>
3.插入的这句话的意思
3.1docBase表示你项目的实际地址,也就是在电脑中的实际存储位置,而path代表虚拟地址(虚拟地址的意思是你想让项目放在那个位置但是不移动项目在电脑的存储位置),它有两种写法,因为你想将该项目放到webapps下面而你又不想移动你的项目,所以说第一种写法就是相对路径,相对于webapps来说的,webapps是根目录即"/myJsp2",或者你可以写绝对路径"D:\apache-tomcat-7.0.68\webapps/myJsp2"