How to run a servlet program?

Answer Posted / vivek

To run a servlet one should follow the steps illustrated below:

Download and Install the tomcat server: Install the tomcat server in a directory in which you want to install and set the classpath.for the variable JAVA_HOME in the environment variable. To get details about the installation process and setting the classpath click the link Tomcat installation.


Set the class for the jar file: Set the classpath of the servlet-api.jar file in the variable CLASSPATH inside the environment variable by using the following steps.

For Windows XP,
Go to Start->Control Panel->System->Advanced->Environment Variables->New button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar

For Windows 2000 and NT

Go to Start->Settings->Control Panel->System->Environment Variables->New button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar

Create a java source file and a web.xml file in a directory structure.
Compile the java source file, put the compiled file (.class file) in the classes folder of your application and deploy the directory of your application in the webapps folder inside the tomcat directory.
Start the tomcat server, open a browser window and type the URL http://localhost:8080/directory (folder name of your application) name/servler name and press enter.

If everything is correct your servlet will run.

Is This Answer Correct ?    8 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is Servlet so popular?

613


What is lazy loading and what is Generic Servlet Class?

607


What are the common methods that are included in the http servlet class?

576


What is the requirement of servlet config and servlet context implemented and how are they implemented?

539


How are filters?

580






why we should override only no-agrs init() method.

676


What is a server side include (ssi)

568


What is the type of method for sending request from http server?

594


What is the advantage of Servlets when compared with other server side technologies?

1853


What is session tracking?

696


What does the term localization refer to?

580


Write a hello world program using servlets.

590


What is servlet in tomcat?

557


How to get the current httpsession object?

649


What’s the difference between genericservlet and httpservlet?

528