Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Apache JServ 1.0 : (Category) Programming and Misc. Tidbits :
How do I debug my servlets?

----------
From: Luc Saint-Elie lse@imaginet.fr
To: "Java Apache Users" java-apache-users@list.working-dogs.com
Subject: Re: How to debug servlets in jserv?
Date: Wed, Jul 21, 1999, 4:43 PM


I didn't try it.. but lutris (http://www.enhydra.org) just released a free 
servlet debugger.. you may want to have a look at it.

Le 15:44 21/07/99 -0600, Dave King a écrit:
>I'm sure this is a FAQ question (it was on the Java Web Server Mailing
>list) and I promise to add it to the FAQ-O-Matic when I find out how.
>
>In the java web server you could run it as a console app and you'd see
>the System.out messages.  Doesn't seem to work with apache on NT.
>
>log() works but I'm wondering if  anyone has details on attaching a
>debugger to jserv or other debuging sugestions.
>
>I'm using JDK 1.2.1 on NT.
>
>-Peace
>Dave

+------------------------------------------------+
| Luc Saint-Elie                                 |
| 75018 Paris France                             |
| Tel: 1(212)894 3713 ext: 0012                  |
| email : luc@interpasnet.com                    |
+------------------------------------------------+
| Java Server Side Open Source technologies      |
| http://www.interpasnet.com/JSS                 |
+------------------------------------------------+
----------
From: Andy John andy@Enhydra.ORG
To: java-apache-users@list.working-dogs.com
Subject: Re: How to debug servlets in jserv?
Date: Wed, Jul 21, 1999, 11:17 PM


When I needed to see stdout from my servlet, I set up JServ so that
the backend was running in a "normal" VM that I started.

In Apache's httpd.conf, set ApJServManual to "on". Now when Apache
starts up, it won't fire up a VM to run the back end. Of course,
servlets are now broken until you do it manually...

Then I wrote my own shell script to start the VM. This is on Unix,
your milage may vary. Here's what it does:

#!/bin/sh
JAVA=/usr/local/jdk1.1.7/bin/java
CLASS=org.apache.jserv.JServ
CP=/u/shawntmp/aj10/src/java/ApacheJServ.jar:/usr/local/jsdk2.0/lib/jsdk.jar
http/jserv-demo-80/EnhydraDebugger/enhydra.jar
CONF=/u/http/jserv-demo-80/conf/jserv.properties
CLASSPATH=$CP
export CLASSPATH
$JAVA $CLASS $CONF


Since you start the VM "normally", when your servlet writes to stdout, you 
will see it.




There is another option.... :)
You could try the EnhydraServletDebugger!
This is a servlet that you run in addition to your problem servlet (in the
same zone). You connect to it and run the debugger (the front end is an
applet). You then connect to your own servlet through the debugger, and
it logs all the requests.

This would not show output to stdout. It does not set breakpoints, or step
through your code. It does show you all the detail of the request, the
response, the output (if html or text), and every call your servlet made
to the request/response API (including the results given to your servlet).

So, for example, you would be able to see that your serlvet is asking for
a list of all headers, and see what was given to it. Then you notice that
one of them is spelled differently than you thought. Aha!!!

We have used this kind of debugging for a year now, and it has saved us
many many hours of frustration. Your servlet must be running enough to
handle responses for it to be useful, of course.

Here is some screenshots, so you can get a feel for it:

Request details:   http://www.enhydra.org/media/screenshots/SADebuggerRequest.gif
Servlet API trace: http://www.enhydra.org/media/screenshots/SADebuggerTrace.gif
Response details:  http://www.enhydra.org/media/screenshots/SADebuggerResponse.gif


Here is where to download it:

http://www.enhydra.org/cuts/EnhydraServletDebugger_b1.zip

See the file README.html for installation instructions.

Hope this helps!
   Andy
Just a quick follow up to Andy's note:

Andy notes that ApJServManual is in httpd.conf but on a new install it's in 
jserv.conf in the Apache Group/Apache JServ/conf dir. The install has
httpd.conf include jserv.conf.

On NT I used the following comand line:
java -cp C:\PROGRA~1\APACHE~1\APACHE~1\ApacheJServ.jar org.apache.jserv.JServ C:\PROGRA~1\APACHE~1\APACHE~1\conf\jserv.properties

-Peace
Dave
Thanks to Andy John's post on controlling the VM from scripts and setting ApJServManual 
to "on" I was inspired to get IBM/Alphaworks' Jikes debugger (an all java visual debugger, 
drill down on Java from http://alphaworks.ibm.com/tech/) working with Jserv to complement 
my Emacs/JDE (http://sunsite.auc.dk/jde/) environment. 

I set all my classpath and such in a modified Jikes startup script:

#!/bin/sh
# jd involks Jikes debugger
# Set JD and JDK to match the appropriate installation directories on your system.
# Jikes wants a classpath passed it, it and sourcepath can be altered while running

JD=/home/ted/bin/jikesdb/jd.zip
JDK=/usr/local/jdk116_v5/lib/classes.zip
CP=$CLASSPATH
set -x
java "-Deditor=emacs +%L %F" -classpath $CP:$JD:$JDK jd.Main -classpath $JD:$CP:$JDK $* 
#yes it's got hooks into emacs as well

and start jserv like this:

#!/bin/sh
jd org.apache.jserv.JServ /usr/local/apache/conf/jserv.properties

I can then set breakpoints in any object or servlet anywhere in my class and 
source paths and see how things are when it gets called in a url.
P.S. Jikes debugger is free and well worth the look.

ted@guilds.net
I have been able to use JBuilder 3 on Windows NT to debug my servlets.

First, I downloaded JServ.java from WebCVS and added it to my project.
Next, I set JServ.java to be the default runnable file in the project properties.
Next, in the project properties I added c:\path2jerv\conf\jserv.properties to 
the parameters.

Set your breakpoints, start debugging (Shift+F9), and you're off!!

Scott Sanders
scott@eionline.com
[Append to This Answer]
Previous: (Answer) Displaying images with servlets...
Next: (Answer) getDateHeader("If-Modified-Since") always returns -1
This document is: http://java.apache.org/faq/?file=257
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.