Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debugging Servlets -- Help

 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the best way to debug a servlet under Tomcat when you don't have access to the STDERR.LOG and STDOUT.LOG files (or catalina.log) files?
The way I normally debug a servlet is to look at the STDOUT.LOG files for the output of my System.out.println() commands. However, since I don't have access to these logs on the commercial web server, this approach won't work.
Is a good way to just write to a text file on the web server (in a directory you do have rights to) using java File classes?
I'm interested to hear any thoughts or ideas to debug a servlet that works fine under localhost, but fails on the actual web server (where I don't ahve access to the logs I need).
Thanks in advance to all!
-- Mike
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For one suggestion - if you are just serving HTML - make sure every exception in your doGet or doPost is caught and try to return a HTML page with the full stack trace. (Hint - format with < pre >
Bill
 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
Sorry, not so simple. The code that doesn't work on the web server is a class that generates JPEG files....no doGet() or doPut() in scope, unfortunately.
Do you think creating a local file from the JPEG writer class based on what's happening in the JPEG-writer class (for example "You're now about to execute the write" type messages).
Look forward to your reply.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I would write a log to a StringWriter and make the resulting String accessible to another servlet or possibly to another function in the same servlet. So if your JPG generator serves an image on doGet you could add a doPost that shows the most recent log string. I have occasionally had debugging functions built in to servlets this way - naturally with some sort of password required.
Bill
 
Mike London
Ranch Hand
Posts: 1208
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
-- Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic