Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

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.

"Which server should we use?" is a common question, and the honest answer depends on what you are comparing. Some tools are other Java servlet containers (Jetty, Undertow), some are full application servers (WildFly, Payara, Open Liberty) and some are web servers or proxies that do not run Java at all (Apache httpd, Nginx). Tomcat sits between them: it runs Java web apps but is far lighter than a full Jakarta EE server.

This lesson puts them side by side, explains standalone versus embedded Tomcat, and ends with a small program that scores options against your requirements.

Three categories

Three kinds of server

Servlet container Tomcat, Jetty, Undertow
Application server WildFly, Payara, Liberty
Web server / proxy Nginx, Apache httpd

They are often combined, not exclusive.

1 / 2

Servlet containers: Tomcat, Jetty, Undertow

All three implement the Servlet specification, so the same servlet code runs on each. The differences are about packaging and style:

  • Tomcat is the most widely used, with the largest body of documentation, books and operational know-how. It is configured through XML files and is usually installed as a standalone server hosting several apps, though it is just as often embedded.
  • Jetty is designed to be embedded and configured in code. It is popular in tools, build plug-ins, Eclipse components and frameworks that want a small HTTP stack.
  • Undertow (from the WildFly project) is a fast, non-blocking server with a builder-style API; it powers WildFly and can be used inside Spring Boot.

For ordinary applications the performance differences are small compared with the cost of your own code and database. Pick by familiarity, ecosystem and operations.

Full application servers

WildFly (Red Hat), Payara (a GlassFish derivative), Open Liberty (IBM) and similar servers implement the whole Jakarta EE platform: CDI, EJB, JPA, JMS, JTA, security, batch and more, in one product with a management console. Choose one when you want those standardized services out of the box, or your company already runs them. Choose Tomcat when your application is a web tier built on libraries (Spring, Hibernate, JPA with a standalone provider), because you stay in charge of each dependency and the server remains small.

Apache httpd and Nginx

These are not Java servers. They shine at serving static files, terminating TLS, compression, caching, rate limiting and balancing traffic across several back ends. In production it is very common to put one of them in front of Tomcat as a reverse proxy:

flowchart LR
    B["Browser"] --> N["Nginx or httpd<br/>TLS, caching, static files"]
    N --> T1["Tomcat A<br/>port 8080"]
    N --> T2["Tomcat B<br/>port 8080"]
    T1 --> DB[("Database")]
    T2 --> DB

A typical layout: the proxy faces the internet; Tomcat instances run the Java code behind it.

Tomcat can terminate TLS itself and serve static files well, so a proxy is not mandatory. You add it for operational reasons: one entry point for many apps, easy zero-downtime rolling restarts, a hardened public-facing process and familiar tooling for the operations team. The connectors lesson shows the Tomcat side of the connection.

Standalone versus embedded Tomcat

There are two ways to use the same engine:

Standalone (classic) Embedded (Spring Boot style)
Deliverable A .war file An executable .jar
Who starts Tomcat You, with catalina.sh or a service Your main method
Several apps per server Yes Usually one app per process
Configuration server.xml, context.xml, web.xml application.properties or code
Good for Shared hosting of many apps, strict ops separation Microservices, containers, simple deployment

Embedded Tomcat is the same code as the standalone product, started through the org.apache.catalina.startup.Tomcat class. This course focuses on the standalone server because it exposes every concept (contexts, hosts, connectors, valves) that embedded setups hide behind properties. The knowledge transfers: Spring Boot's server.tomcat.* settings tune the same connector and thread-pool values you will learn in connectors and thread pools.

Here is a read-only look at the embedded API:

Java
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();                       // creates the default HTTP connector
Context ctx = tomcat.addContext("", new File(".").getAbsolutePath());
Tomcat.addServlet(ctx, "hello", new HelloServlet());
ctx.addServletMappingDecoded("/hello", "hello");
tomcat.start();
tomcat.getServer().await();                  // keep the JVM alive

A decision helper

The next program is a stand-in: it scores options against weights you set. It is not a benchmark, just a way to make your own criteria explicit. Change the weights and re-run.

Java Score server options against your requirements (stand-in)

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 of the output is the lesson: a score cannot override a hard requirement. If you need to run Java servlets, the proxy-only entry is disqualified.

A second look: how a proxy hands over a request

When Nginx forwards a request to Tomcat, it should tell Tomcat the original host, scheme and client address through headers such as X-Forwarded-For and X-Forwarded-Proto. Tomcat's RemoteIpValve reads them (see logging and access logs). This stand-in shows the header rewrite logic in plain Java.

Java Trusting forwarded headers (stand-in for RemoteIpValve)

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 third call shows why you only trust the header from known proxies: any client could send X-Forwarded-For itself.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which statement about Tomcat and WildFly is correct?

    WildFly is a full application server. Tomcat covers servlets, JSP, EL and WebSocket.
  2. 2. Why is Nginx often placed in front of Tomcat?

    A reverse proxy handles public-facing concerns and spreads load. Tomcat can serve HTTP alone, so a proxy is an operational choice.
  3. 3. What is the deliverable of an embedded (Spring Boot style) Tomcat application?

    Embedded setups package the app and the server library into one executable JAR started with java -jar.
  4. 4. Why should Tomcat only trust X-Forwarded-For from known proxies?

    Clients can set any header, so an untrusted peer's X-Forwarded-For could fake an address in logs or access rules.

Summary

  • Tomcat is a servlet container: lighter than full application servers, more capable than proxies.
  • Jetty and Undertow are alternative containers; WildFly, Payara and Liberty are full Jakarta EE servers; Nginx and httpd are proxies and static servers.
  • A reverse proxy in front of Tomcat is common but optional.
  • Standalone Tomcat hosts WARs; embedded Tomcat lives inside your executable JAR and uses the same engine.
  • Forwarded headers must be trusted only from known proxies.

Next: How a request travels through Tomcat