Java Servlet

Edited by Lim Siong Boon, last dated 22-Sep-2010.

email:    contact->email_siongboon  


Running Java Servlet
1- Download Tomcat

Download apache-tomcat-7.0.2, 32-bit/64-bit Windows Service Installer (Binary Distributions)
Download old version apache-tomcat-6.0.29, 32-bit/64-bit Windows Service Installer (Binary Distributions)

Please visit the website to download distributions for other operating system.

2- Install Tomcat Install the downloaded Tomcat installer.
You would be instruct to key in an optional user name and password.
Please key in and remember your password.

Test if the Tomcat is install properly by running the program Tomcat Monitor.
Start>All Programs>Tomcat 7.0>
Tomcat Monitor

A Tomcat notification icon will appears in the taskbar (bottom right corner of the screen).
Right click the icon, and select "Start Service" to start running the Tomcat server.
Open a web-browser and go to the following URL "http://localhost:8080"
Localhost is the same as the ip address of your local machine.
Port: 8080 is the default port serve by the Tomcat.
If the IP address of your computer is, the URL is

You should see the following Tomcat start up webpage on your browser if the tomcat is installed correctly.

This indicates that the Tomcat server is installed successfully and is working fine.

click to enlarge

Right click the icon on the taskbar, and select "Stop Service" to stop the Tomcat server.
Try re-loading the
URL "http://localhost:8080". The browser will try loading for some time.
You will receive a connection or error message indicating that the page cannot be found.
There is no server listening on port 8080, therefore any request to the site will have no response.

If Tomcat main webpage is not display, please check again if your tomcat server is started.

3- Placing a Java servlet on the Tomcat server.
Download the ready made servlet "".
Unzip and copy the WebDBA project folder to "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\". This is the folder to put our java servlet project folder. The project contains a standard directory structure, containing the java *.class files.

Click on the Tomcat Manager link on the main webpage.
You will be prompt for user name and password which you had during the Tomcat installation process.
The following page will be displayed with the list of services running on the Tomcat server.
You should be able to see the "WebDBA" project on the list.
The tomcat server would automatically load the projects found on the \Tomcat 7.0\webapps\ folder.
Ensure that the WebDBA service is started; click on the "Start" link in the command column.

click to enlarge

If the servlet is not on the list, try stop the Tomcat server, and then start it again. Refresh the webpage and check if the servlet project is listed.

4- Running the Java servlet.
Open a web-browser and go to the following URL "http://localhost:8080/WebDBA/Hi"
You should be able to see the following replied response screen-shot from your HTTP Get request.

click to enlarge

If the servlet is not running or the URL is incorrect, you might see the following error response.
Refer to the previous steps to ensure that the WebDBA service is started.

click to enlarge

5- Your Java Servlet will begin here.
Congratulation. Now that you have learned running a servlet on the Tomcat server, you can run your java classes on top of this servlet example. Learn how to just log4j logger to help you log messages for your learning and debugging purpose.

Please follow other servlet examples to learn writing your own servlet.

Writing Java Servlet

make own servlet, generate your own web.xml. MANIFEST.MF is generated automatically when you do *.war packaging