Java
  Home arrow Java arrow Page 2 - Debugging Servlets
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Debugging Servlets
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2006-09-28

    Table of Contents:
  • Debugging Servlets
  • How to print debugging data to the console
  • How to write debugging data to a log file
  • Perspective

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

    More Java Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach's Java Servlets and JSP," published...
     

    Buy this book now. This article is excerpted from chapter five of the book Murach's Java Servlets and JSP, written by Andrea Steelman and Joel Murach (Murach; ISBN: 1890774189). Check it out today at your favorite bookstore. Buy this book now.

    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...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT