The process of Tomcat processing an http request --- complete reproduction

When Tomcat accepts a request and returns the processing result, the general process is that the Connector processes the request into request and response objects and passes them to the Cantainer. The Cantainer implements processing according to the four child containers of the parent-child relationship, and returns the results to the Connector after the meeting. Return to the client.

Insert picture description here
Connector (connector) is used to handle connection-related matters, and provides conversion between Socket and Request and Response;
Container (container) is used to encapsulate and manage Servlet, and specifically process Request requests;

1. Connector (connector) internal specific Implementation
Insert picture description here
2: Request processing process in tomcat
Suppose the request from the customer is:
http://localhost:8080/wsota/wsota_index.jsp

  1. The request is sent to port 8080 of the local machine and is obtained by the Coyote HTTP/1.1 Connector listening there
  2. The Connector passes the request to the Engine of the Service where it is located for processing, and waits for the response from the Engine
  3. Engine gets the request localhost/wsota/wsota_index.jsp, matching all the virtual hosts it owns Host
  4. The Engine matches the Host named localhost (even if it fails to match, the request will be handed over to the Host for processing, because the Host is defined as the default host of the Engine)
  5. localhost Host gets the request /wsota/wsota_index.jsp, matching all the Context it owns
  6. Host matches the Context whose path is /wsota (if it fails to match, hand over the request to the Context whose path name is "" for processing)
  7. The Context of path=”/wsota” obtains the request /wsota_index.jsp, and looks for the corresponding servlet in its mapping table
  8. Context matches the servlet whose URL PATTERN is *.jsp, corresponding to the JspServlet class
  9. Construct HttpServletRequest object and HttpServletResponse object, call the doGet or doPost method of JspServlet as parameters
  10. Context returns the HttpServletResponse object after execution to Host
  11. Host returns the HttpServletResponse object to the Engine
  12. Engine returns the HttpServletResponse object to the Connector
  13. Connector returns the HttpServletResponse object to the client browser

Guess you like

Origin blog.csdn.net/Wangdiankun/article/details/105821421