What Is Tomcat

Introduction

Apache Tomcat is an open-source Servlet container that runs Java web applications. It implements the Jakarta Servlet specification: your code handles HTTP through Servlets, Filters, and (optionally) JSP pages, and Tomcat manages connections, threads, and deployment. This chapter explains what Tomcat is, where it sits in a Java stack, and how this tutorial track complements the Spring Boot and Maven courses on Hello Code.

Prerequisites

  • Basic Java syntax (classes, packages, main)
  • Idea of HTTP (browser sends a request, server returns a response)
  • No Tomcat installation required yet for this overview
  • Helpful background: What Is Spring Boot, Maven WAR packaging

Tomcat in One Sentence

Tomcat is a lightweight web container that listens on a port (default 8080), maps URL paths to deployed applications, and executes Servlet code inside a managed JVM process.

Most teams encounter Tomcat in one of these ways:

RoleWhat Tomcat does
Standalone serverRuns one or more WAR files you deploy to webapps/
Embedded containerBundled inside Spring Boot as an executable JAR (java -jar app.jar)
Behind a reverse proxyListens on 127.0.0.1:8080 while Nginx handles public HTTPS
Legacy Java web hostHosts Spring MVC or plain Servlet apps without Spring Boot

This track focuses on standalone Tomcat: install, directories, configuration, and WAR deployment—not only the embedded mode you see in Spring Boot logs.

A Typical Request Path

text
  Browser                    Tomcat                     Your Servlet
     │                         │                          │
     │  GET /hello/world       │                          │
     ├────────────────────────►│                          │
     │                         │  dispatch to web app     │
     │                         ├─────────────────────────►│
     │                         │◄─────────────────────────┤
     │◄────────────────────────┤     HTML / JSON          │
     │   200 OK                │                          │

Code explanation:

  • Tomcat accepts the TCP connection and parses the HTTP request
  • Each deployed app has a Context path (e.g. /hello)—the URL prefix that routes to that WAR
  • Tomcat invokes the matching Servlet (or static file handler) and writes the response

Tip

Context Path Matters

A WAR named hello.war usually maps to http://localhost:8080/hello/, not the site root. The ROOT app is the special case for /.

Servlet Container vs Application Server

TermScopeExamples
Servlet containerServlet, JSP, WebSocket (web profile)Tomcat, Jetty
Full application serverServlets plus EJB, JMS, full Jakarta EEWildFly, Payara, WebLogic

Tomcat is intentionally lean. It runs web applications well but is not a full Jakarta EE server. Many production stacks pair Tomcat with Spring (Boot or MVC) for business logic, data access, and security—without needing a heavyweight app server.

Embedded vs Standalone Tomcat

ApproachHow it runsTypical output
Embedded (Spring Boot default)Tomcat starts inside your JAR via SpringApplication.runTomcat started on port(s): 8080 in Boot logs
StandaloneYou install Tomcat, copy a WAR to webapps/, run startup.shSeparate process; one Tomcat hosts many apps
text
  Embedded                         Standalone
  ─────────                        ──────────
  java -jar app.jar                bin/startup.sh
       └── Tomcat inside JAR            └── Tomcat process
            └── one app                      └── webapps/app1.war
                                               └── webapps/app2.war

Code explanation:

  • Embedded simplifies development and cloud deploy—one artifact, one command
  • Standalone suits ops teams that manage one shared container, multiple WARs, or strict separation between app and server upgrades
  • Spring Boot supports both: executable JAR (embedded) or WAR deployed to external Tomcat

The Spring Boot track teaches embedded Tomcat by default. This Tomcat track teaches installation, directory layout, server.xml, and WAR deployment—the skills you need when Tomcat is its own service on a VPS.

Tomcat vs Jetty vs Undertow

ContainerNotesCommon pairing
TomcatMost widely used; Apache project; strong docsSpring Boot default, traditional WAR deploy
JettySmall footprint; embeddableSome Boot apps, Google App Engine style
UndertowRed Hat–backed; used in WildFlySpring Boot alternative (spring-boot-starter-undertow)

For Hello Code—learning Java web deploy on Linux, WAR packaging with Maven, and Nginx in front—Tomcat is the natural default.

Jakarta Servlet: Tomcat 10 vs Tomcat 9

Tomcat major versions align with Servlet API package renames:

TomcatServlet API packagesJDK (typical)
9.xjavax.servlet.*Java 8+
10.1.xjakarta.servlet.*Java 11+ (17+ recommended)
11.xjakarta.servlet.* (Servlet 6+)Java 17+

This track uses Tomcat 10.1.x with Spring Boot 3 and Jakarta EE 9+. If you maintain legacy apps on javax.*, you may still run Tomcat 9 until libraries migrate.

Warning

Boot 3 and Tomcat 10 Go Together

Spring Boot 3 requires Jakarta-compatible dependencies. Deploying a Boot 3 WAR to Tomcat 9 will fail unless you target an older Spring generation.

Common Scenarios on Hello Code

Your projectHow Tomcat helps
Spring Boot WAR (not executable JAR)Deploy to Tomcat webapps/ on a server
Plain Servlet + Maven first project warClassic Java web learning path
Spring MVC without BootWAR on Tomcat; web.xml or Java config
Production VPSTomcat on 127.0.0.1:8080, Nginx on 80/443
Local learningUnzip Tomcat, drop a WAR, open http://localhost:8080/

Tomcat does not replace your framework—it hosts the WAR your build produces. You still write Java, package with Maven or Gradle, and configure routing in Spring or web.xml.

What Tomcat Is Not

  • Not a full database — use MySQL or another store; Tomcat can expose JNDI DataSources but does not store business data itself
  • Not a replacement for Spring Boot — Boot adds auto-configuration, starters, and embedded server choice; Tomcat is the runtime underneath
  • Not Nginx — Tomcat runs Java web apps; Nginx often sits in front for TLS, static files, and load balancing
  • Not required for every Spring Boot dev sessionspring-boot:run uses embedded Tomcat locally; standalone install matters when you deploy WARs or operate a shared server

Core Concepts You Will See Later

ConceptMeaning
CATALINA_HOMETomcat installation directory (bin/, lib/, default webapps/)
CATALINA_BASEInstance-specific config and deploy dirs (multi-instance setups)
ConnectorNetwork endpoint in server.xml (HTTP port 8080, etc.)
HostVirtual host; default localhost with appBase="webapps"
ContextOne deployed application and its URL path
WARWeb application archive—WEB-INF/, classes, libraries, static files

Directory details live in Installing Tomcat and Directory Layout and Tomcat Directory Layout.

How This Tutorial Is Organized

This Tomcat track follows frontend/gen_article_plan/tomcat.md:

  1. Install and directories — JDK, unzip, bin/ / conf/ / webapps/, start and stop
  2. Configurationserver.xml, web.xml, context.xml, users and roles
  3. Deployment — WAR vs exploded directory, Manager app, external docBase
  4. Servlet basics — lifecycle, JSP, Filters (container-native API)
  5. Logs, security, proxy — AccessLogValve, hardening, Nginx proxy_pass
  6. Spring integration — Boot WAR on external Tomcat vs embedded JAR
  7. Projects and troubleshooting — Maven WAR deploy, Nginx + Tomcat, FAQ

Examples assume Tomcat 10.1.x and JDK 17+. Linux paths use /opt/tomcat or tar.gz layouts; Windows uses zip installs. Package-manager paths differ by distro and are noted when relevant.

Tip

Pair With Linux and Nginx

Use the Linux track for SSH, systemd, and firewall basics. Use Nginx when Tomcat should not face the public internet directly. Modern SPAs often use Vue dist/ on Nginx with proxy_pass to Tomcat or Spring Boot APIs.

Mini Example: What a Deployed App Looks Like

You do not need to run this yet—it previews the shape of a minimal web app:

text
hello.war  (or webapps/hello/)
├── index.html              ← static file at /hello/index.html
├── WEB-INF/
│   ├── web.xml             ← optional in Servlet 3+ with annotations
│   ├── classes/            ← compiled .class files
│   └── lib/                ← application JAR dependencies

A Servlet mapped to /world inside that app is reached at:

text
http://localhost:8080/hello/world

Code explanation:

  • hello is the context path (from the WAR file name unless configured otherwise)
  • /world is the Servlet path inside the application
  • Tomcat serves static files from the WAR root; dynamic code runs from WEB-INF/classes and WEB-INF/lib

Later chapters build this with Maven, deploy to webapps/, and trace requests in the logs.

FAQ

Is Tomcat free?

Yes. Apache Tomcat is open source under the Apache License 2.0. No license fee for development or production.

Do I need Tomcat if I already use Spring Boot?

For local development, usually no—Boot embeds Tomcat. You need standalone Tomcat when you deploy a WAR to a shared server, operate Tomcat as a separate service, or learn classic Java web operations.

Tomcat vs Spring Boot—which should I learn first?

Learn Spring Boot first if your goal is modern REST APIs and fast project setup. Learn standalone Tomcat when you deploy WARs, maintain legacy Servlet apps, or run multiple apps on one JVM host.

What port does Tomcat use by default?

8080 for HTTP. HTTPS (if configured on Tomcat itself) often uses 8443. In production, Nginx commonly listens on 443 and proxies to Tomcat on localhost.

Can Tomcat run PHP or Node.js?

No. Tomcat runs Java web applications (Servlets/JSP and frameworks built on them). Other runtimes use their own servers or process managers.

Tomcat 9 or Tomcat 10 for a new project?

Choose Tomcat 10.1+ with Jakarta (jakarta.*) if you use Spring Boot 3 or new libraries. Use Tomcat 9 only for existing javax.* applications.

Is Tomcat the same as Apache httpd?

No. Apache httpd is the classic Apache HTTP web server (often used with PHP). Apache Tomcat is a separate project focused on Java Servlets. Both names include "Apache" because they are Apache Software Foundation projects.

What is the difference between this track and Spring Boot logs mentioning Tomcat?

Spring Boot embeds Tomcat inside your JAR—you rarely touch webapps/ or server.xml. This track teaches operating Tomcat as its own server: directories, config files, deployment, and pairing with Nginx.