Java
  Home arrow Java arrow Page 4 - The JSP Files (part 7): Bugs, Beans And Banks
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
JAVA

The JSP Files (part 7): Bugs, Beans And Banks
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2001-04-18


    Table of Contents:
  • The JSP Files (part 7): Bugs, Beans And Banks
  • Bugathon
  • Exceptionally Clever
  • Bad News
  • You Throw(), I'll Catch
  • Bean Bag
  • Turning Up The Heat

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    The JSP Files (part 7): Bugs, Beans And Banks - Bad News
    ( Page 4 of 7 )

    The exception-handling routine "error.jsp" can be as simple or complex as you want to make it. If you want something friendly and easy to understand, you could use the following:

    <html> <head> <basefont face="Arial"> </head> <body bgcolor="white"> <h2>Oops!</h2> Something bad just happened. Click here to go back to the main page. </body> </html>

    Now, if you run the example above again, JSP should automatically divert you to this page instead of grossing you out with long and icky error messages.

    The script above simply notifies the user that an error has occurred; it says nothing about the type of error, or the reasons for its occurrence. If you'd like to display this as well, you need to use the built-in Exception object to obtain information about the exception. The next example uses a modified "error.jsp" to illustrate this:

    <%@ page isErrorPage="true" %> <html> <head> <basefont face="Arial"> </head> <body bgcolor="white"> <h2>Oops!</h2> Something bad just happened: <br> <b><i><%= exception.getMessage() %></i></b> </body> </html>

    And this time, the output will be a little more helpful.

    Oops! Something bad just happened: / by zero

    Pay special attention to the first line of the script; the directive

    <%@ page isErrorPage="true" %>

    tells JSP that this is an error page, and initializes an instance of the Exception object for use.

    The Exception object comes with a couple of useful methods - the exception.getMessage() method is used to obtain a description of the error, while the exception.printStackTrace() method is used to print debugging information.

     
     
    >>> More Java Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek