Wednesday, August 12, 2009

What are Good Ways of Debugging a Servlet ? Are are IDE's which support Servlet Debugging ?

There are couple of Methods. Firstly servers like JRun and others provide separate logs where all your Print requests will print their data into. For example requests to System.out. and System.err go to different log files. If this features is not available or you want to maintain logs separately for each module then you can create a static class called "LogWriter" and call the method inside the try catch loop. The print method in Log Writer will be writing to a custom defined Log File.

try
{ ....
}
catch(Exception exp)
{
LogWriter.print("Debug : The following error occurred at function .... ')
}

Also Inprise JBuilder supports Servlet Debugging. Please refer to JBuilder documentation for details.

Just as a Cautionary note, from your Servlets, never call System.exit(0). The results might be unpredictable. Might close down the entire Server. The Best way is to catch the Exception and either send resultant Error Page to the Browser or Write to a Log file and inform user about the Error.

No comments:

Post a Comment