This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Need an IDE or debugger! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need an IDE or debugger!" Watch "Need an IDE or debugger!" New topic

Need an IDE or debugger!

bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
Can anyone please tell me the best way to debug an simple html which is calling a servlet which then calls a bean?
I tried downloading SUN ONE and ECLIPSE, but found the installation instructions too vague!
Is there another way to debug these kinds of components please?
Thanks very much!
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
System.out.println() works when you need to debug and don't have an IDE/debugger to help

My Java Freeware:<br />MACCC - <a href="" target="_blank" rel="nofollow"></a><br />Nator - <a href="" target="_blank" rel="nofollow"></a>
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
In my experience, by far the best way to debug a servlet application is to remove the bugs before they get to the server.
Step 1: unit test your bean to death on its own, make sure there are no problems with this "simple" bit.
Step 2: move any code not to do with processing HTTP (that's the business of GET's and parameters and stuff) to a regular Java class which you call from the servlet code. Unit test your new class to death, make sure there are no problems in this code either. If this code is generating HTML, test that it is generating the correct HTML when it has the correct parameters passed in, etc.
Step 3: Put some diagnostic prints in your servlet so that it prints out the parameters about to be passed in to the regular Java code, and whetever information comes out. Deploy and run your servlet, grab the printed diagnostic data and compare it with your unit test data. If the "live" parameters are different from your tests, add new tests which test your code when supplied with the actual parameters you logged. Rinse and Repeat with different user input until you are happy that the extracted Java "business code" works.
Step 4; When you are happy, remove the diagnostic prints from teh servlet code, and redeploy the final application with the corrected business code.
If you use this approach, you should only need to deploy your servlet application to a server twice - once with diagnostics, once without. All other testing and debugging is done with regular java tools on regular Java classes.
I hope this makes sense. I have used this technique successfully in many projects.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Great answer Frank. It shows using Tests, decoupling classes to makes it easier to debug and later maintain and enhance.
I'd much rather take that time up front like you post, than trying to fix it on the other side, like Bob is finding out.
Good Luck Bob, and take Frank's advice.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Need an IDE or debugger!
It's not a secret anymore!