Home Servlets How to run a servlet



How to run a servlet
Posted on: July 13, 2007 at 12:00 AM
In this section, you will learn how to run servlets.

How to Run a Servlet

     

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.

 

Related Tags for How to run a servlet:
javacclasstomcatserverantprocessinstallationpathdirectoryiovariablegetlinkinstallclasspathenvironmentviclickcliriaaisetfortotailproceilhomelslivarceinassspstamntoutwancajclesdirdetailsallmeprocatenvdetaildetailtorwhichsrectspctordirectessatkirinkironllmcandarrvsettingwantvattssrocrithavstabablatictoprocesprndonomo


More Tutorials from this section

Ask Questions?    Discuss: How to run a servlet   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.