Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Apache Tomcat?

Learn what Apache Tomcat is, what a servlet container does, what Tomcat includes and leaves out, and how a tiny container works, with runnable Java stand-ins.

Apache Tomcat is an open-source web server and servlet container written in Java. You give it a web application (a folder or a .war file containing servlets, JSP pages, static files and configuration) and it listens on a network port, turns incoming HTTP requests into Java objects, calls your code, and writes your response back to the browser. Tomcat is developed by the Apache Software Foundation and is one of the most widely deployed Java web servers in the world.

If you have used a framework such as Spring MVC, Jakarta Faces or Struts, Tomcat is very likely the thing that was running underneath. In this first lesson you learn what Tomcat is responsible for, what it deliberately does not do, and why the idea of a "container" matters. The real Tomcat cannot run on this site, so Tomcat code and configuration files are shown read-only, and the runnable examples are small stand-ins written in plain Java that reproduce the underlying mechanics.

What a servlet container does

A servlet is a Java class that handles requests. You never start it with main. Instead, the container does the work you would otherwise repeat in every project:

  • It opens server sockets and speaks the HTTP protocol (parsing request lines, headers and bodies; building responses).
  • It manages a pool of threads, so many requests are handled at once.
  • It creates your servlets and calls init, service and destroy at the right time (the servlet lifecycle).
  • It keeps sessions for visitors, usually with a cookie named JSESSIONID.
  • It maps URLs to servlets and filters using the rules in web.xml or annotations.
  • It isolates each web application with its own class loader, so two apps can use different versions of the same library.
  • It offers shared resources through JNDI, such as database connection pools.

In Jakarta EE terms Tomcat implements the web-tier specifications that matter most: Servlet, Jakarta Server Pages (JSP), Expression Language, WebSocket and the Authentication (JASPIC) API. It is not a full application server: it has no built-in EJB container, JMS broker or JTA transaction manager. You add those with libraries when you need them, or get them from servers like WildFly and Payara.

What Tomcat gives you

HTTP Sockets, parsing, TLS
Threads Many requests at once
Servlets Lifecycle and mapping
Sessions State per visitor

Your code only handles the business logic.

1 / 2

Tomcat, Catalina, Coyote and Jasper

Tomcat is made of named parts, and you will meet the names in logs and configuration:

Name Role
Catalina The servlet container itself: engines, hosts, contexts, the lifecycle.
Coyote The connector layer that speaks HTTP/1.1, HTTP/2 and AJP.
Jasper The JSP engine that compiles .jsp pages into servlets.
Cluster, WebSocket, JULI Session replication, WebSocket support and the logging implementation.

The architecture lesson shows how they nest. For now, remember that "Catalina" shows up in folder names and environment variables (CATALINA_HOME) even though the product is called Tomcat.

A container in 40 lines

The program below is a miniature container built on the JDK's own HttpServer. It registers "servlets" (plain functions) under URL paths, starts a thread pool and then calls itself with an HttpClient. Tomcat does the same job with far more care: thousands of connections, timeouts, security and standards. The point is that the shape is identical.

Java A miniature container (stand-in, not Tomcat)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The thread name differs from main: the container, not your code, chose the thread. In Tomcat the names look like http-nio-8080-exec-3 (protocol, port and worker number).

What HTTP looks like to the connector

Before any servlet runs, a connector reads bytes and builds a request. This stand-in sends a hand-written HTTP request over a raw socket and prints what a very small server parses: the request line, then each header.

Java Parsing a raw HTTP request (stand-in for a connector)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The last line previews an important Tomcat idea: the first segment of the path (/shop) selects the web application (the context path), and the rest (/items) is matched against that app's servlets. You will explore it in WAR files and the webapps folder.

A first look at real Tomcat

A real servlet looks like this. It is shown read-only because the Tomcat classes are not available here.

Java
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import java.io.IOException;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/plain;charset=UTF-8");
        resp.getWriter().println("Hello from Tomcat");
    }
}

Package that class into hello.war, copy it to Tomcat's webapps folder and the page appears at http://localhost:8080/hello/hello. The first web application lesson walks through every step.

Tomcat is often called "a web server". It does serve static files, but its strength is running Java web applications. In front of a busy site it is usually paired with a reverse proxy such as Nginx or Apache httpd; see Tomcat compared with other servers.

Common misunderstandings

  • "Tomcat is a framework." No. Spring, Struts and Jakarta Faces are frameworks that run inside it. Tomcat only provides the container.
  • "Tomcat is a full Jakarta EE server." It implements the web-tier specifications, not EJB, JMS or JTA.
  • "Tomcat and Catalina are different programs." Catalina is Tomcat's container engine; they ship together.
  • "I need Tomcat to run Spring Boot." Spring Boot embeds Tomcat (by default) as a library inside your own JAR, so you start your app with java -jar.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which task does a servlet container such as Tomcat perform for you?

    The container owns the sockets, HTTP parsing, thread pool, servlet lifecycle and sessions. Databases and e-mail are things you add.
  2. 2. What is Coyote in Tomcat?

    Coyote is the connector layer. Jasper compiles JSP pages, Catalina is the servlet container and JULI is the logging implementation.
  3. 3. Which Jakarta EE service is NOT included in Tomcat?

    Tomcat implements the web tier (Servlet, JSP, EL, WebSocket). JMS messaging needs a separate broker or a full application server.
  4. 4. In the path /shop/items, which part normally identifies the web application?

    The first path segment is the context path, here /shop. The remaining path is matched against that application's servlet mappings.

Summary

  • Tomcat is an open-source Java servlet container and web server from the Apache Software Foundation.
  • It handles HTTP, threads, the servlet lifecycle, sessions, URL mapping and class-loader isolation.
  • Catalina is the container, Coyote the connectors, Jasper the JSP engine.
  • It implements the web tier only: no EJB, JMS or JTA.
  • Frameworks run inside Tomcat, and Spring Boot can embed it.
  • The runnable examples in this track are plain-Java stand-ins that mirror how the real parts work.

Next: Tomcat versions and Java compatibility