tomcat 虚拟目录

tomcat 虚拟目录

介绍:tomcat 虚拟目录的实战
需求:基于tomcat的虚拟目录,玩一下,修改url名称:localhost:8080-->www.baidu.com.cn:8080
步骤:
1.在tomcat的根目录下的conf目录,修改server.xml,添加如下节点:
<Host name="www.baidu.com.cn"  appBase="webapps2"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false" >
            <Context path="/" docBase="/web" />
      </Host>

2.在tomcat根目录下创建webapps2,子目录web,分别对应虚拟目录里面的 appBase,docBase
3.在web目录内新增WEB-INF目录,新增一个web.xml,以及新增一个test.html,内容分别如下:
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
<welcome-file-list>
    <welcome-file>test.html</welcome-file>
  </welcome-file-list>
  <error-page>
  	<error-code>500</error-code>
  	<location>/error.html</location>
  </error-page>
</web-app>
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>hello world</h1>
</body>
</html>

4.修改本地的hosts文件,目录是在C:\WINDOWS\system32\drivers\etc\hosts。
添加如下内容:
127.0.0.1       www.baidu.com.cn


5.基本工作完成了,然后启动tomcat,网址输入:www.baidu.com.cn。哈哈结果出来了.注意,我这边是因为修改了tomcat的启动端口为80,是浏览器访问的默认端口,所以不需要在url内输入端口号,哈哈,这样是不是更逼真?

6.结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值