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! BC
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: unittest 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.
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. Mark