Web Server, Web Container and Application Server

HTTP Server

A web server is software that helps to deliver web content (web pages) to the clients (e.g. web browser) through the Internet using HTTP protocol. HTTP is a simple request /response protocol underpinning most web applications on the Internet, regardless of whether they are written in Java. An HTTP request can correspond to one of the seven HTTP methods: GET, POST, HEAD, OPTIONS, TRACE, PUT and DELETE. You can read more about the seven methods @ the note the-seven-http-methods. The server side technologies like JSP/Servlets, ASP, and PHP etc. will require their software libraries to be installed at the server. Without these libraries a web server won’t be able to execute those server technologies and is just an HTTP Server. An HTTP server can handle HTML and other client side technologies which don’t require any server capability. The Apache HTTP Server is an example of an HTTP server.


Web containers (or Servlet containers), Servlets and JSPs

JSPs/Servlets cannot be executed on a HTTP Server. To deploy and run JSPs/Servlets, a compatible web server with a servlet container, such as Apache Tomcat or Jetty, is required. A servlet container is usually referred to as a web container. A web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights.

Servlets are java classes executed on the server and are used to generate dynamic web pages. You can use print statements within servlet to print html tags and html data to the browser. Java Server Page (JSP) is a server side technology based on java that help us to create dynamically generated web pages based on HTML, XML etc. easily. While servlets can be considered as java classes with html, JSPs can be considered html pages with java. JSPs are eventually converted into servlets by the server before execution. We will see servlets and JSPs in detail later.


Application Servers and Enterprise JavaBeans (EJB)

A web container like apache tomcat or jetty just implements the JSP and Servlet specification of Java EE. However there are more specifications within Java EE, mainly the EJB specification. A servlet container implements only the JSP and Servlet specification, and doesn’t implement EJB specification. Hence we cannot deploy and execute EJB applications in a servlet container like Apache Tomcat or Jetty. Instead you need a full application server. An application server contains an EJB container as well as servlet container and implements all the required specifications of Java EE. Examples of application servers are Glassfish Application Server, which is a Java EE reference implementation from Oracle, Websphere Application Server by IBM, JBoss Application Server by Red Hat inc etc.

A special note, Java EE was previously referred to as J2EE 1.x (e.g. J2EE 1.4), but with version 5 it is now referred to as Java EE X or JEE X where X is the version number (e.g. JEE 5). Still many people refer to the specification as J2EE due to its widespread popularity. This website was named as JavaJEE after this announcement.

Enterprise JavaBeans (EJB) is a managed, server-side component architecture to handle common concerns in enterprise applications such as persistence, transactional integrity, and security in a standard way, leaving programmers free to concentrate on the particular problem at hand. There are basically two types of EJBs: Session bean and Message Driven Bean. Session Beans are business objects that can be accessed via either a Local (same JVM) or Remote (different JVM) interface or directly without an interface. Session beans can be either "Stateful", "Stateless" or "Singleton". Stateful Session Beans are business objects having state: that is, they keep track of which calling client they are dealing with throughout a session. Stateless Session Beans are business objects that do not have state associated with them. Singleton Session Beans are business objects having a global shared state within a JVM. Message Driven Beans are business objects whose execution is triggered by messages instead of by method calls. For instance, a message driven bean can listen on an Websphere MQ queue and get triggered when a message is put on the queue. Entity bean was also a type of EJP in previous versions of the EJB specification. However it is deprecated in the latest version in favor of the Java Persistence API (JPA).


Lightweight alternatives to EJB

With lightweight java frameworks like Spring and Hibernate, you really doubt if it is worth to go for the extra overhead with the EJBs. You can get most of the functionality that EJBs provide through spring and hibernate with less overhead and less learning time. Main advantage here is that you don’t need an application server like Glassfish, Websphere Application Server or JBoss, when you use spring or hibernate. A web container like tomcat can be used instead just by adding the required library jars into the classpath.   



An HTTP server can handle only html files. A web container or servlet container can handle Servlets and JSPs. An application server contains a web container and ejb container and can handle Servlets, JSPs and EJBs. EJBs can be deployed only on Application Servers, but not on web containers. Spring and hibernate are lightweight alternatives to EJBs and can be deployed on a web container as well.







Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)