JavaWeb学习笔记(2)——虚拟路径和虚拟主机
虚拟路径
将web项目配置到webapps以外的目录
方式一:
docBase:实际路径
Path:虚拟路径(绝对路径,相对路径【相对于webapps】)
在conf/server.xml中配置
host标签中添加:
缺点:需要重启Tomcat
方式二:
在conf目录下的Catalina中的localhost中
新建“项目名.xml”中新增一行:
虚拟主机
通过www.test.com访问本机
a.
在conf/server.xml中添加:
<Engine name=”Catalina” defaultHost=”www.test.com”>//在上面的Engine中修改defaultHost
<Host appBase=”.....” name=”www.test.com”>
<Context docBase=”.......” path=”/”>
</Host>
b.
在C:\Windows\System32\drivers\etc\Host
中增加
127.0.0.1 www.test.com
流程:
www.test.com->host找映射关系->server.xml找Engine的defaultHost->通过“/”映射