• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to test servlets?

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 java.sun.com - 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.
Bill

------------------
author of:
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 myprog.java'
so what is the command to compile servelet?
Don't forget to answere my first question!!!
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
javac myfile.java
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!
Annette
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class files for the servlets that come with tomcat are in :
....tomcat\webapps\examples\WEB-INF\classes
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:
http://localhost:8080/examples/servlets/
and that worked.
I assume this path is stored in the web.xml file, but I haven't gotten into that yet.
HTH
[This message has been edited by eric moon (edited December 20, 2000).]
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 myservlet.java) but there are errors whereever
I have use word 'httpservlet' in my example that 'cannot resolve symbol'.
Where I'm wrong now?
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be u have forgotten to import javax.servlet.http.* .Just check it up
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are the imported files:
import java.io.*;
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.
reply
    Bookmark Topic Watch Topic
  • New Topic