Apache Tomcat Tutorial
Learn Apache Tomcat step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Tomcat Versions and Java Compatibility Understand which Tomcat release matches which Servlet API, Jakarta EE namespace and Java version, and how to choose a version and migrate from javax to jakarta.
- Your First Tomcat Web Application Build and deploy a first Tomcat web application: project layout, a servlet, web.xml, packaging a WAR, deploying it and reading the URL, with runnable WAR stand-ins.
- Tomcat Compared with Other Servers Compare Apache Tomcat with Jetty, Undertow, WildFly, Payara, Apache httpd and Nginx, and with Spring Boot embedded Tomcat, to decide where Tomcat fits in your stack.
- How a Request Travels Through Tomcat Follow an HTTP request through Tomcat: connector, engine, host, context, valves, filters and servlet. See the mapping steps and build a pipeline stand-in in Java.
Architecture and Install
- Installing Tomcat Install Apache Tomcat step by step: check Java, download and verify the archive, unpack it, set JAVA_HOME, start the server, test port 8080, and use packages or Docker.
- The Tomcat Directory Layout Explore every folder in a Tomcat installation: bin, conf, lib, logs, temp, webapps and work. Learn what each configuration file does and which folders are safe to delete.
- Catalina Architecture: Server, Service, Engine, Host, Context Understand Tomcat's component hierarchy: Server, Service, Connector, Engine, Host, Context and Wrapper, how server.xml describes them, and parse a server.xml with Java.
- CATALINA_HOME and CATALINA_BASE Learn the difference between CATALINA_HOME and CATALINA_BASE, how to run several Tomcat instances from one installation, set up a base folder, and upgrade safely.
- Starting and Stopping Tomcat Learn the Tomcat launch scripts, catalina.sh commands, setenv.sh with CATALINA_OPTS and JAVA_OPTS, the shutdown port protocol, systemd and Windows services, and graceful shutdown.
Deployment and Contexts
- WAR Files and the webapps Folder Learn how Tomcat deploys WAR files and folders from webapps: context path rules, ROOT.war, versioned names, unpackWARs, autoDeploy, deployOnStartup and common deployment mistakes.
- Context Descriptors and context.xml Learn the Tomcat Context element: where context descriptors live, docBase and path rules, META-INF/context.xml versus conf/Catalina/localhost, precedence, and common attributes.
- Virtual Hosts in Tomcat Configure several domains in one Tomcat with Host elements: name, aliases, appBase, defaultHost, separate logs per host, and test host routing with a Java stand-in.
- Class Loading in Tomcat Understand Tomcat's class loader hierarchy: bootstrap, system, common and webapp loaders, why web apps load their own classes first, where to place JARs, and how class loader leaks happen.
- The Manager App and Parallel Deployment Use Tomcat's Manager application to deploy, reload and undeploy apps from a browser or curl, secure its roles and access, and run several versions of an app in parallel with ##version names.
Configuration
- Connectors and Thread Pools Configure Tomcat connectors: HTTP/1.1 and AJP, port, protocol, maxThreads, acceptCount, maxConnections, timeouts, compression, HTTP/2 and shared Executors, with Java stand-ins that model queues.
- web.xml, Defaults and URL Mapping Understand the global conf/web.xml and your app's WEB-INF/web.xml, the DefaultServlet and JspServlet, url-pattern matching rules, welcome files, error pages and session timeout.
- JNDI Resources and Connection Pools Configure a container-managed JDBC DataSource in Tomcat with JNDI: Resource in context.xml, resource-ref in web.xml, lookup code, pool settings, global resources and connection leaks.
- Logging and Access Logs in Tomcat Understand Tomcat's log files, JULI configuration in logging.properties, log levels and rotation, application logging, and the AccessLogValve pattern with a Java formatter stand-in.
Security and TLS
- Realms and Authentication in Tomcat Learn how Tomcat realms, tomcat-users.xml and security-constraint rules in web.xml protect URLs, and how BASIC, FORM and DIGEST login work.
- TLS and HTTPS in Tomcat Configure HTTPS in Tomcat 11: keystores, the SSLHostConfig and Certificate elements, protocols, ciphers, HTTP/2, redirects and certificate renewal.
- Hardening Apache Tomcat for Production A practical Tomcat hardening checklist: remove default apps, run as a non-root user, shut down the shutdown port, hide version info and lock down error pages.
- Valves, Filters and Access Control in Tomcat Learn the difference between Tomcat valves and servlet filters, then restrict access by IP with RemoteCIDRValve, add security headers and the CSRF prevention filter.
Clustering and Sessions
- Sessions and Session Persistence in Tomcat Understand how Tomcat stores HttpSession data, what the session manager does, how sessions survive restarts, and which settings control timeout and cookies.
- Session Replication and Clustering in Tomcat Learn how Tomcat clusters replicate HttpSession data between nodes, the difference between DeltaManager and BackupManager, membership, jvmRoute and distributable apps.
- Load Balancing Tomcat and Sticky Sessions Put several Tomcat nodes behind a load balancer: algorithms, jvmRoute sticky sessions, health checks, proxy headers, and zero-downtime draining of a node.
Monitoring and Tuning
- Monitoring Tomcat with JMX and the Manager Learn how Tomcat exposes metrics through JMX MBeans, how to enable remote JMX safely, which attributes matter, and how the Manager status page and JVM beans help.
- Thread Pools and Connector Tuning in Tomcat Understand how Tomcat's NIO connector handles requests, what maxThreads, acceptCount and maxConnections mean, how keep-alive and timeouts work, and how to size a pool.
- JVM Memory and Garbage Collection Tuning for Tomcat Set Tomcat's JVM heap, choose a garbage collector, read GC logs and avoid OutOfMemoryError with practical setenv.sh flags and runnable Java examples.
- Tomcat Access Logs and Request Metrics Configure the Tomcat AccessLogValve, choose a log pattern with response time, rotate files and compute error rates and percentile latency from access logs.
Troubleshooting
- Reading Tomcat Logs and Stack Traces Learn which Tomcat log files exist, what each records, how to read a Java stack trace and its Caused by chain, and how to adjust log levels with logging.properties.
- Common Tomcat Startup and Deployment Errors Diagnose the most common Tomcat problems: address already in use, wrong JAVA_HOME, ClassNotFoundException, jakarta vs javax, failed contexts, 404 after deploy and 403 on the manager.
- Memory Leaks, Thread Dumps and Deadlocks in Tomcat Find Tomcat classloader and ThreadLocal memory leaks after redeploys, take and read thread dumps, spot stuck and deadlocked threads, and capture heap dumps.
Projects and Practice
- Project: Review a Production server.xml Build a server.xml linter in Java that parses the XML and flags risky settings, then use its report to harden and tune a Tomcat configuration step by step.
- Project: Zero-Downtime Deployment on Tomcat Deploy new versions of a web app without dropping sessions using Tomcat parallel deployment, version numbers in WAR names, health checks and a rollback plan.
- Project: Build a Mini Servlet Container Build a tiny servlet-style web container in Java with context paths, a filter chain, cookie sessions and a worker pool, to understand how Tomcat handles requests.
- Tomcat Practice Exercises and Interview Questions Practice Tomcat operations with sizing exercises and runnable Java calculators, then review common Tomcat interview questions on security, clustering, tuning and troubleshooting.