What is a Servlet Container? Apache Tomcat Installation

To use Servlets and JSPs is necessary the use of a "Servlet Container". There are a lot of Servlet Containers like Apache Tomcat, Jboss, etc. For this tutorial we will use Tomcat because the rest of them are based in Tomcat.

What is a Servlet?

A Servlet is a java object from a class which extends from javax.servlet.http.HttpServlet. This is not exactly true because there is different types of Servlets but HttpServlet is clearly the most used.

What is a Servlet Container?

A Servlet Container is a program which can receive requests from web pages and redirect those requests to a Servlet object.

How does this Servlet Container work?

  1. The Browser asks the HTTP server for a page, which is a Servlet Container.
  2. The Servlet Container delegates the request to a particular Servlet chosen between the Servlets it contains.
  3. The Servlet, which is a java object, is in charge of generating the text of the web page delivered to the container.
  4. The container returns the web page to the Browser which made the request.

Download Apache Tomcat

The Tomcat server has been developed by "Apache Software Foundation" http://apache.org/. This community is so important that it could be responsible for java success. It has a lot of interesting projects but without a doubt the most important is and will be Tomcat.

We can download the container from http://tomcat.apache.org/

Among the Windows versions there is one zip version and another one with a Windows service installer. As I want to keep this tutorial as simple as possible, I will use the zip version and leave the explanation of what is a Windows service for another tutorial :) We download the zip (32 or 64bit) and we decompress it in C:\.

In the installation, inside the folder bin\ we wil find startup.bat, with which we can start the server.

We have to take into account that Tomcat depends on java so it will look for the system variable JAVA_HOME which will indicate where is the java installation. Example: JAVA_HOME=" C:\Program Files\Java\jdk1.6.0_21"

Once the server is started we can see if it works with any Browser writing http://localhost:8080 and we should something like:

Inside de folder webapps\ we create a folder first-servlet\ which will be the name of our web aplication and inside it we create a file named welcome.html with the following content:



<title>Hola Mundo</title>



      <h1>Hola edu4java</h1>

      <p>Bienvenidas a nuestra primera <br/> página Web. </p>



We go back to the Browser and point to http://localhost:8080/first-servlet/welcome.html and we should obtain:

I have to point out that the name of the project and the page are written in lower case. As a convention, everything which appears in URL should be in lower case.

<< Index First Servlet, website structure according to J2EE standards. >>