Introduction to Tomcat

2019-09-23

[Tomcat source code](https://github.com/apache/tomcat)

Tomcat source code

Reading the Tomcat source code Tomcat architecture

What This Covers

  1. Tomcat structure diagram
  2. Tomcat startup process
  3. Tomcat request handling process

1. Tomcat structure

  • Service
    • Connector
      • Container
        • Engine
          • Host
            • Context
              • Wrapper: corresponds to one Servlet class

2. Tomcat startup process

3. Tomcat request handling process

  • Data arrives on a local port and is picked up by the Connector
    • Connector: listens for TCP connection requests on the port
      • Creates the Request and Response
      • Spawns a thread to pass the request to Container.Engine
        • The Container’s Engine receives the request and hands it to the Host
          • The Host receives the request and hands it to the Context
            • The Context receives the request, matches the Servlet, and hands it over
              • Constructs the HttpServletRequest and HttpServletResponse
            • Context returns the HttpServletResponse to the Host
          • Host returns the HttpServletResponse to the Engine
        • Engine returns the HttpServletResponse to the Connector
    • Connector returns the HttpServletResponse to the Browser