HOW TO: Setup Java Servlets in my JSP/Servlet enabled web hosting account ?

To help you get started, we are providing an example web.xml and servlet class you can use to try out a servlet. Place this web.xml in the following directory:


(replace 'username' with your account's username.)

Place the servlet Java code in the following directory and compile it to the servlet class:


(You will need to create these directories if they do not exist already.)

Once you've saved the web.xml and created the servlet class, it will take just a moment for Tomcat to begin serving the servlet. Access the URL:


And you should see the servlet's output. "Hello World!"

(You will need to replace '' with your web site's domain name. and replace the port number '8080' with your Tomcat instance's port number. Typically the Tomcat port number is 4 or 5 digits and ends in 80. Examples include: 8080, 9580, 10080)

Here is the sample web.xml file we used:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"


<!-- General description of your web application -->

<display-name>My Web Application</display-name>
This is version X.X of an application to perform
a wild and wonderful task, based on servlets and
JSP pages. It was written by Dave Developer
(, who should be contacted for
more information.

<!-- Context initialization parameters that define shared
String constants used within your application, which
can be customized by the system administrator who is
installing your application. The values actually
assigned to these parameters can be retrieved in a
servlet or JSP page by calling:

String value =

where "name" matches the <param-name> element of
one of these initialization parameters.

You can define any number of context initialization
parameters, including zero.

The EMAIL address of the administrator to whom questions
and comments about this application should be addressed.

<!-- Servlet definitions for the servlets that make up
your web application, including initialization
parameters. With Tomcat, you can also send requests
to servlets not listed here with a request like this:


but this usage is not guaranteed to be portable. It also
makes relative references to images and other resources
required by your servlet more complicated, so defining
all of your servlets (and defining a mapping to them with
a servlet-mapping element) is recommended.

Servlet initialization parameters can be retrieved in a
servlet or JSP page by calling:

String value =

where "name" matches the <param-name> element of
one of these initialization parameters.

You can define any number of servlets, including zero.

Hello World!

<!-- Define mappings that are used by the servlet container to
translate a particular request URI (context-relative) to a
particular servlet. The examples below correspond to the
servlet descriptions above. Thus, a request URI like:


will be mapped to the "graph" servlet, while a request like:


will be mapped to the "controller" servlet.

You may define any number of servlet mappings, including zero.
It is also legal to define more than one mapping for the same
servlet, if you wish to.


<!-- Define the default session timeout for your application,
in minutes. From a servlet or JSP page, you can modify
the timeout for a particular session dynamically by using
HttpSession.getMaxInactiveInterval(). -->

<session-timeout>30</session-timeout> <!-- 30 minutes -->



Here is our sample source file:


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletException;

public class Hello extends HttpServlet
public void service(HttpServletRequest _request,
HttpServletResponse _response) throws ServletException, IOException

ServletOutputStream out = _response.getOutputStream();

out.println("<br><head><br><title>Hello World!<br></title><br></head>");
out.println("<br><h1>Hello World!<br></h1>");

public String getServletInfo()
return "HelloServlet";


The following URL will give detailed directions on how you need to setup a web.xml file to get your servlets to work with Tomcat:



  • Email, SSL
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What is the difference between shared SSL and private SSL?

A shared SSL displays as https://ip/~yourusername/. A private SSL would display as...

Why are my FrontPage extensions not working?

You must first make sure you have installed the extensions from going into your cpanel and...

Application Paths

Here are the applications paths. If you do not see what you are looking for, please email...

Custom error pages

To create a custom error page for your account you will need to upload a file with the...

How do I use SSL to setup my email?

Set your mail server to the host name for SMTP/POP3/IMAP (instead of and then make...