tomcat服务器 虚拟映射以及组成结构

虚拟映射

方法一

server.xml 文件Host节点下添加Context节点

<Context path="test" docBase="E:\wangdao\testX_Y(test就是应用,这个docBase就是所指向的应用文件夹的位置)"></Context> 
path就是应用名   docBase就是该应用所指定的路径

在浏览器中输入 localhost:8080/test/ 加上想打开的文件

方法二(重要)

在 conf/Catalina/localhost目录下增加一个 应用名.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<Context docBase="E:\wangdao\testX_Y(应用的路径)"></Context>

优先级最高

修改tomcat所监听的端口号
server.xml文件中修改。可以修改为80(前1024个端口不要修改,除了80以外)

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Tomcat组成结构

在这里插入图片描述

  1. 向浏览器输入http://localhost:8080/third/1.txt,浏览器生成一个请求报文
  2. 从应用层向下传递,到达目标机器后再向上传递。
  3. 会在8080端口中交给connector,connector会生成一个request对象和response对象交给engine
    engine会根据其url,把两个对象交给指定的host
  4. host挑选对应的Context来处理(从webapps或者server.xml或者conf/catalina/localhost中得到)
    Context处理请求,发现请求是要1.txt文件,将文件内容写入response,没有则返回404.
  5. connector读取response内容后生成响应报文。再传回去
  6. 浏览器渲染呈现画面

如何通过ip直接访问资源

  • 首先解决端口问题。如果不写端口,默认端口是80。所以先把端口改为80;
    再解决应用问题。其中涉及到直接部署和虚拟映射。
    若是直接部署:
  • 不写应用的情况下,默认是访问ROOT目录,所以把webapps中你所要访问的应用名称改为ROOT。
  • 若是虚拟映射:
    则采用虚拟映射的方法二,创建一个ROOT.xml
    没有指定要访问的资源,则该资源应该设置为默认资源
    在conf/ web.xml / 最下方设置
<!-- ==================== Default Welcome File List ===================== -->  <!-- When a request URI refers to a directory, the default servlet looks  -->  <!-- for a "welcome file" within that directory and, if present, to the   -->  <!-- corresponding resource URI for display.                              -->  <!-- If no welcome files are present, the default servlet either serves a -->  <!-- directory listing (see default servlet configuration on how to       -->  <!-- customize) or returns a 404 status, depending on the value of the    -->  <!-- listings setting.                                                    -->  <!--                                                                      -->  <!-- If you define welcome files in your own application's web.xml        -->  <!-- deployment descriptor, that list *replaces* the list configured      -->  <!-- here, so be sure to include any of the default values that you wish  -->  <!-- to use within your application.                                       -->
    <welcome-file-list>
            <welcome-file>index.html</welcome-file>        
            <welcome-file>index.htm</welcome-file>        
            <welcome-file>index.jsp</welcome-file>    
   			<welcome-file>xxx</welcome-file>
    </welcome-file-list>

————————————————
版权声明:本文为CSDN博主「Rul丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_46330379/article/details/108086400

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值