Home arrow Java arrow Page 2 - Debugging Servlets
JAVA

Debugging Servlets


Last week, you learned about working with servlets. This week, you will learn how to debug servlets. This article, the last of three parts, is excerpted from chapter five of the book Murach's Java Servlets and JSP, written by Andrea Steelman and Joel Murach (Murach; ISBN: 1890774189).

Author Info:
By: Murach Publishing
Rating: 2 stars2 stars2 stars2 stars2 stars / 3
September 28, 2006
TABLE OF CONTENTS:
  1. · Debugging Servlets
  2. · How to print debugging data to the console
  3. · How to write debugging data to a log file
  4. · Perspective

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Debugging Servlets - How to print debugging data to the console
(Page 2 of 4 )

If you’re using Tomcat in a stand-alone development environment, you can print debugging messages to the console for the servlet engine as shown in figure 5-10. To do that, you can use the println method of the System.out and System.err objects. You can use these message to help track the methods that are executed or the changes to variables.

If you aren’t using Tomcat in a stand-alone environment, you might not be able to view the debugging messages in the console. In some cases, though, you may be able to make them appear in the console by starting the servlet engine from a command line. In other cases, the println statements may automatically be written to a text file that you can view. Otherwise, you’ll need to print this data to a log file as described in the next figure.

When you use println statements to check the value of a variable, you’ll often want to include the name of the class and the name of the variable. That way, your messages will be easier to understand. This also makes it easier to find and remove the println statements once the error is debugged.

How Tomcat displays printin statements


Figure 5-10  How to print debugging data to the console

Code that prints debugging data to the console

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
                    throws IOException, ServletException{
    // code
    String emailAddress = request.getParameter("emailAddress");
    System.out.println("EmailServlet emailAddress: " + emailAddress);
    // code
 
}

Description

  • When you’re testing an application on your local system, you may be able to use the println method of the System.out or System.err objects to display debugging messages on the console for the servlet engine.
  • When you use debugging messages to display variable values, it’s a good practice to include the class name and variable name so the messages are easy to interpret.


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials