aspose file tools*
The moose likes Servlets and the fly likes How to test servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to test servlets?" Watch "How to test servlets?" New topic

How to test servlets?

Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
I have downloaded tomcat 3.1 .Tomcat's default page is displaying from browser.I have gone through some documents in its docs
directory to how to install and run tomcat but it is very
lenghty and technical for a new user.My question is again
the same that which else software is required to test servlet
or no other is required?Second question is where can I store
and how can I compile servlets?
Lisa Strite

Joined: Dec 19, 2000
Posts: 4
I have not used TomCat, I am using WebSphere but I believe it is similar. You can compile your servlets using whatever jdk the tomcat server runs (probably 1.2.1 or 1.2.2). You will probably then copy them into the 'servlet' directory. Then you will start the Tomcat server. You will test your servlets by entering in a web browser "http://localhost/servlet/MyServletName".
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12675
Just to supplement Lisa's comments..
If your servlet does not require any user input, you can call it directly. However, most servlets are built as part of a larger application so you will typically have to provide HTML pages with <form> elements to be filled in by the user, etc.
The Java API for servlets lays out exactly where class files have to be kept in relation to the other elements of a web application. Download that API from - It does get complicated, but you can follow the examples that Tomcat provides.
You need to understand how the web.xml file is used to control the way Tomcat refers to servlets and to provide initialization parameters.

author of:

Java Resources at
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
When you say "software to test servlets" do you mean just the software to run them so you can test them manually, or are you looking for automated test tools?
For manual tests you just need a reasonable servlet container (Tomcat, Resin, JRun, Weblogic, etc.) For automatic tests you could try HTTPUnit, but it's a notoriously difficult area.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
Ok,as far as I understand,to compile a servelet I
have to go in 'tomcat/src/javax/servlet' directory and
there I can save and complile my servelets?
Second question is, as for compiling java
programs we give at the prompt 'javac'
so what is the command to compile servelet?
Don't forget to answere my first question!!!
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
I'm not using Tomcat, but I'm trying to learn servlets as well. The way I've been able to test them is to compile them exactly as you would a normal .java file. That is at the command prompt, type:
or if you're using some kind of software, like I'm using Jbuilder, I just compile it from the menu.
But once that's done, you move the .class file that was created after you compiled the .java file to the /servlet directory. Then from a web browser you type http://localhost/servlet/myfile
(replace localhost with the url to your web server where you saved your file followed by the path to where you saved your .class file).
This worked for me up till now, so I hope it works for you too!
eric moon
Ranch Hand

Joined: Nov 26, 2000
Posts: 133
The class files for the servlets that come with tomcat are in :
The way I tested my servlet was to compile it and put it in that directory, go to the servlet example page in tomcat, and rename the reference of one of their examples to point to my servlet instead.
If your servlet creates a form, that's not the address to put in the form. I looked at the URL displayed in my browser for their examples:
and that worked.
I assume this path is stored in the web.xml file, but I haven't gotten into that yet.
[This message has been edited by eric moon (edited December 20, 2000).]

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>"Those who cast the votes decide nothing. Those who count the<BR>votes decide<BR>everything." <BR> -Joseph Stalin<HR></BLOCKQUOTE>
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
As per your advices,I save and compile
my servlet in jdk1.2/bin directory(where I save
and compile my other java files) and compile it
with command (javac but there are errors whereever
I have use word 'httpservlet' in my example that 'cannot resolve symbol'.
Where I'm wrong now?
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
May be u have forgotten to import javax.servlet.http.* .Just check it up
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
These are the imported files:
import javax.servlet.*;
import javax.servlet.http.*;
then why its giving error,'can't resolve symbol'.
Steps I followed to save and compile servlet are right?which
I wrote in my previous reply.
I agree. Here's the link:
subject: How to test servlets?
Similar Threads
J2EE - Question / SCWCD - question
How to test a servlet.
Servlets with Tomcat 4
debugging applets that communicate with servlets in tomcat
Java application inside tomcat?