Java.Servlet.Why do we need application servers if we have servlet containers?

Yes — servlet containers like Tomcat can run web applications… so why do we need application servers like WildFly, GlassFish, or Payara?

Let’s break it down:


🧩 1. Servlet Containers (e.g., Tomcat, Jetty)

Only support the Web part of the Java EE (Jakarta EE) specification:

  • Servlets (HttpServlet)
  • JSP (JavaServer Pages)
  • WebSocket
  • Basic authentication, session management

Good for:

  • Simple web apps
  • REST APIs
  • Frontend + backend with just servlets and JSP

💼 2. Application Servers (e.g., WildFly, GlassFish)

Support full Java EE / Jakarta EE spec:

In addition to everything a servlet container does, they support:

FeatureAPI
Dependency InjectionCDI (Contexts and Dependency Injection)
Transaction ManagementJTA (Java Transaction API)
SecurityJAAS, role-based access
Enterprise BeansEJB (Enterprise JavaBeans)
MessagingJMS (Java Message Service)
PersistenceJPA (Java Persistence API)
Batch JobsJSR 352
Web ServicesJAX-RS, JAX-WS

Good for:

  • Complex enterprise-grade apps
  • Apps that need distributed transactions, messaging, etc.
  • Legacy systems using full Java EE stack

🔍 Example Scenario

TaskServlet Container (Tomcat)Application Server (WildFly)
Serve HTML, handle forms✅ Yes✅ Yes
REST API with JSON✅ Yes✅ Yes
Background jobs, timers❌ No✅ Yes (via EJB Timer)
Messaging with JMS❌ No✅ Yes
Distributed transactions❌ No✅ Yes
Dependency injectionLimited (manual)✅ Built-in with CDI

💡 Spring Boot Bonus

Spring Boot apps embed a servlet container (like Tomcat or Jetty) and provide application server-like features via Spring libraries:

  • @Component, @Service, @Transactional
  • No need for full Java EE server

So with Spring Boot, you get many of the benefits of an application server with a lightweight setup.


🧠 TL;DR

FeatureServlet ContainerApplication Server
Lightweight✅ Yes❌ Usually heavier
Fast startup✅ Yes❌ Slower
Servlets & JSP✅ Yes✅ Yes
Full Java EE support❌ No✅ Yes
Suitable for Microservices✅ Yes❌ Often overkill
This entry was posted in Без рубрики. Bookmark the permalink.