Home arrow Java & J2EE arrow Page 4 - The JSP Files (part 7): Bugs, Beans And Banks

Bad News - Java

In this week's episode, find out how the JSP Exception objectprovides developers with a graceful way to recover from script errors. Andthen take a quick tour of the JSP directives you need to know in order tointegrate standalone JavaBeans into your JSP scripts.

TABLE OF CONTENTS:
  1. The JSP Files (part 7): Bugs, Beans And Banks
  2. Bugathon
  3. Exceptionally Clever
  4. Bad News
  5. You Throw(), I'll Catch
  6. Bean Bag
  7. Turning Up The Heat
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 2
April 18, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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 & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: