Apache Tomcat is an open-source web server and Servlet Container developed by the Apache Software Foundation. While often called an "Application Server," it is technically a web server designed specifically to execute Java Servlets and render JavaServer Pages (JSP).
Unlike a full Java EE application server (like JBoss or WebLogic) which supports the entire stack of enterprise features (EJB, JMS, etc.), Tomcat is lightweight and focused purely on the web tier. This makes it the industry standard for hosting Spring Boot applications and microservices.

Key Components
1. Catalina (The Servlet Container)
Catalina is the engine that actually implements the Java Servlet specification. It manages the lifecycle of your servlets (init, service, destroy). When you deploy a .war file, Catalina unpacks it and loads the classes.
2. Coyote (The Connector)
Coyote handles the network communication. It supports HTTP/1.1, HTTP/2, and AJP protocols. It manages the thread pool, creating threads to handle incoming requests efficiently.
3. Jasper (The JSP Engine)
If your application uses .jsp files (JavaServer Pages), Jasper is responsible for parsing them. It compiles the JSP file into a standard Java Servlet (.class file) so that Catalina can execute it. This is why the first load of a JSP page is slow (compilation) but subsequent loads are fast.
Core Architecture: How Tomcat is Built
Tomcat is built hierarchically. Understanding this hierarchy is key to configuring it correctly.
1. Server: The top-level component. It represents the entire Tomcat instance (JVM). It listens for a shutdown command on a specific port (default 8005).
2. Service: A grouping of one or more Connectors that share a single Engine.
- Role: It bridges the outside world (Connectors) with the internal processing logic (Engine).
3. Connector (Coyote): The component that listens for incoming connections.
- HTTP Connector: Listens on port 8080 (default) for standard web traffic.
- AJP Connector: Listens on port 8009 for traffic from a reverse proxy like Apache HTTPD.
4. Engine (Catalina): The brains of the operation. It represents the request processing pipeline. It examines the incoming request headers to determine which Host and Context should handle it.
5. Host: Represents a virtual host (e.g., www.example.com). You can have multiple hosts on one Tomcat server.
6. Context: Represents a single Web Application (e.g., /my-app).
The Request Lifecycle: From Browser to Servlet
What happens when a user types http://localhost:8080/my-app/hello?
- Accept: The Coyote Connector listening on port 8080 accepts the TCP connection.
- Parse: It parses the HTTP headers and creates
HttpServletRequestandHttpServletResponseobjects. - Route (Engine): The Connector passes these objects to the Engine, which looks at the hostname (
localhost). - Route (Host): The Engine passes the request to the matching Host.
- Route (Context): The Host looks at the URL path (
/my-app) and passes the request to the correct Context (your application). - Execute (Servlet): The Context looks at the specific mapping (
/hello) and invokes the corresponding Java Servlet code. - Response: The Servlet writes data to the response object, which travels back up the chain (Context -> Host -> Engine -> Connector) and is sent back to the user's browser.
Tomcat Directory Structure
Knowing where files live is critical for administration.
/bin: Startup (startup.sh) and shutdown (shutdown.sh) scripts./conf: Configuration files.server.xml: The main config (Ports, Connectors, Hosts).web.xml: Default settings for all apps (MIME types, session timeout).tomcat-users.xml: Users and roles for the Tomcat Manager GUI./lib: Global JAR files shared by all applications (e.g., database drivers)./logs: Server logs (catalina.out,localhost_access_log)./webapps: This is where you deploy your applications. Drop a.warfile here, and Tomcat will automatically deploy it./work: Temporary directory where Jasper stores compiled JSP servlets.
Use Cases of Apache Tomcat
The following are some important use-cases of Apache Tomcat:
- Spring Boot Applications: While Spring Boot has an "embedded" Tomcat, under the hood, it is running the exact same Tomcat engine described above.
- Microservices: Because it is lightweight and starts quickly, it is ideal for containerized microservices (Docker).
- Legacy Enterprise Apps: Hosting traditional
.warbased Java applications that use Servlets and JSPs.