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.
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.
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).
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.