You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
obsidian-sync/日常学习/中间件/tomcat/tomcat 处理一个HTTP请求的过程.md

17 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

![[1079203-20190304104037017-1495719611.png]]
1.用户在浏览器中输入网址localhost:8080/test/index.jsp请求被发送到本机端口8080被在那里监听的Coyote HTTP/1.1 Connector获得
2.Connector把该请求交给它所在的Service的EngineContainer来处理并等待Engine的回应
3.Engine获得请求localhost/test/index.jsp匹配所有的虚拟主机Host
4.Engine 匹配到名为localhost的Host即使匹配不到也把请求交给该Host处理因为该Host被定义为该Engine的默认主机名为 localhost的Host获得请求/test/index.jsp匹配它所拥有的所有Context。Host匹配到路径为/test的 Context如果匹配不到就把该请求交给路径名为“ ”的Context去处理
5.path=“/test”的Context获得请求/index.jsp在它的mapping table中寻找出对应的Servlet。Context匹配到URL Pattern为*.jsp的Servlet对应于JspServlet类
6.构造HttpServletRequest对象和HttpServletResponse对象作为参数调用JspServlet的doGet()或doPost(),执行业务逻辑、数据存储等;
7.Context把执行完之后的HttpServletResponse对象返回给Host
8.Host把HttpServletResponse对象返回给Engine
9.Engine把HttpServletResponse对象返回Connector
10.Connector把HttpServletResponse对象返回给客户Browser。
简化:
1.浏览器发起请求后通过IP及端口找到对应的tomcat服务。再通过url找到具体的ServiceConnector将请求交给它所在Service的容器进行处理并等待响应。
2.容器获得请求后开始匹配并解析URL找到对应的Servlet构建HttpServletRequest对象用于处理不同类型的请求GET或POSTServlet返回HttpServletResponse到Connector。
3.Connector 将HttpServletResponse 对象返回给客户端。