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:
| Role | What Tomcat does |
|---|---|
| Standalone server | Runs one or more WAR files you deploy to webapps/ |
| Embedded container | Bundled inside Spring Boot as an executable JAR (java -jar app.jar) |
| Behind a reverse proxy | Listens on 127.0.0.1:8080 while Nginx handles public HTTPS |
| Legacy Java web host | Hosts 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
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
| Term | Scope | Examples |
|---|---|---|
| Servlet container | Servlet, JSP, WebSocket (web profile) | Tomcat, Jetty |
| Full application server | Servlets plus EJB, JMS, full Jakarta EE | WildFly, 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
| Approach | How it runs | Typical output |
|---|---|---|
| Embedded (Spring Boot default) | Tomcat starts inside your JAR via SpringApplication.run | Tomcat started on port(s): 8080 in Boot logs |
| Standalone | You install Tomcat, copy a WAR to webapps/, run startup.sh | Separate process; one Tomcat hosts many apps |
Embedded Standalone
───────── ──────────
java -jar app.jar bin/startup.sh
└── Tomcat inside JAR └── Tomcat process
└── one app └── webapps/app1.war
└── webapps/app2.warCode 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
| Container | Notes | Common pairing |
|---|---|---|
| Tomcat | Most widely used; Apache project; strong docs | Spring Boot default, traditional WAR deploy |
| Jetty | Small footprint; embeddable | Some Boot apps, Google App Engine style |
| Undertow | Red Hat–backed; used in WildFly | Spring 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:
| Tomcat | Servlet API packages | JDK (typical) |
|---|---|---|
| 9.x | javax.servlet.* | Java 8+ |
| 10.1.x | jakarta.servlet.* | Java 11+ (17+ recommended) |
| 11.x | jakarta.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 project | How Tomcat helps |
|---|---|
| Spring Boot WAR (not executable JAR) | Deploy to Tomcat webapps/ on a server |
Plain Servlet + Maven first project war | Classic Java web learning path |
| Spring MVC without Boot | WAR on Tomcat; web.xml or Java config |
| Production VPS | Tomcat on 127.0.0.1:8080, Nginx on 80/443 |
| Local learning | Unzip 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 session —
spring-boot:runuses embedded Tomcat locally; standalone install matters when you deploy WARs or operate a shared server
Core Concepts You Will See Later
| Concept | Meaning |
|---|---|
| CATALINA_HOME | Tomcat installation directory (bin/, lib/, default webapps/) |
| CATALINA_BASE | Instance-specific config and deploy dirs (multi-instance setups) |
| Connector | Network endpoint in server.xml (HTTP port 8080, etc.) |
| Host | Virtual host; default localhost with appBase="webapps" |
| Context | One deployed application and its URL path |
| WAR | Web 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:
- Install and directories — JDK, unzip,
bin//conf//webapps/, start and stop - Configuration —
server.xml,web.xml,context.xml, users and roles - Deployment — WAR vs exploded directory, Manager app, external
docBase - Servlet basics — lifecycle, JSP, Filters (container-native API)
- Logs, security, proxy — AccessLogValve, hardening, Nginx
proxy_pass - Spring integration — Boot WAR on external Tomcat vs embedded JAR
- 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:
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 dependenciesA Servlet mapped to /world inside that app is reached at:
http://localhost:8080/hello/worldCode explanation:
hellois the context path (from the WAR file name unless configured otherwise)/worldis the Servlet path inside the application- Tomcat serves static files from the WAR root; dynamic code runs from
WEB-INF/classesandWEB-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.