Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Servlets How to run a servlet

Related Tutorials


 
 

Share on Google+Share on Google+

How to run a servlet

Advertisement
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.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 13, 2007

Related Tutorials

Discuss: How to run a servlet   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:20
sahil khan
January 26, 2012
java

very nice site beautiful explanation i like you very much thank you raceindia.net
sahil khan
January 26, 2012
java

very nice site beautiful explanation i like you very much thank you raceindia.net
sarthak
January 26, 2012
about this

what is the server name?
Neeraj
January 30, 2012
How to run Servlet

I m trying ur step. thank U sir.
NIKETAN
March 8, 2012
HOW RUN SERVLET PROGRAM

TELL ME HOW RUN SERVLET PROG
yashan
April 24, 2012
sevrlet programin esy

1 )Normal command prompt programin javac -classpath ".;D:\xampp\tomcat\lib\servlet-api.jar" D is my driver path can you install to other driver 2) another is easy to compiling system, it using programmer notepad (this system can using for java compiling) Download for this link (open and free) http://www.pnotepad.org/ following this step 1) Open PP 2) Tool -> option -> select tool tab 3) Select language java to upper tab 4) Selecting add button 5) Filling form 6) Name :- Servelt Command:- E:\Program Files\java\jdk1.6.0_25\bin\javac.exe // JDK javac path Folder :- C:\java // your using or file folder Parameter :- %f -classpath ".;D:\xampp\tomcat\lib\servlet-api.jar" // this copy and paste and changing a driver Ex:- D Shortcut:- F12 // selecting you lick button Save:- current file // or you lick After Ok 1 view -> output or press F8 Ok finish Coding after press F12
MP.Raviprakash Reddy
May 7, 2012
Servlet

i have a problem with compilation of the program and i have tomcat7.0 and it can be placed in c director and the classpath is C:\Tomcat 7.0\lib\servlet-api.jar.The java is placed c drive and the programmin files.what is the problem i have?The java file will be compiling but the server didn't opening the output it can showing errors like 402,500 etc.,
VISWANATH
August 6, 2012
java servlets(runinig of the servlet)

were should i have to write the xml program after completion of the program that has written in not?.. what was use of xml in servlet? how it will excute?thier is any relation between the xml program and the program what has written in the notepad?how thse both excute?
navneet kumar
December 11, 2012
servlet

debugging servlet,runnin servlet,thread safe servlet and what is httpRedirect.
DMCA.com