Tomcat

For the sake of decoupling, the Http server does not call the Servlet directly, but instead hands the request over to the Servlet container

When a client requests a resource, the HTTF server encapsulates the request information with a servletRequest object and then calls the servlet container’s service method. The servlet container gets the request and, based on the mapping between the REQUESTED URL and the servlet, Find the corresponding Servlet, and if the Servlet is not already loaded, create it using the reflection mechanism, call the init method of the Servlet to complete the initialization, and then call the service method of the Servlet to handle the request. The servletResponse object is returned to the HTTF server, which sends the response to the client.

1 Overall Tomcat architecture

  • Connector, which handles Socket connections and is responsible for converting network byte stream Request and Response objects
  • The container loads and manages servlets and handles the transformation of Request objects

1.1 the connector

  • Coyote deals with network communications

    Application layer: HTTP(default) AJP HTTP2

    Transport: After 8.5 move out of BIO This IO model uses NIO(default) NIO2 APR

  • Catalina is responsible for further encapsulating the request response

A container can be composed of multiple connectors to provide external services

Connector assembly

1.2 Container – Catalina

2 Tomcat execution process