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