SunQuest
 
       Java
  Home arrow Java arrow Page 3 - The JSP Files (part 7): Bugs, Beans An...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
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? 
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: 3 stars3 stars3 stars3 stars3 stars / 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:
      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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    The JSP Files (part 7): Bugs, Beans And Banks - Exceptionally Clever


    (Page 3 of 7 )

    There are two basic components to the process of handling JSP exceptions:

    1. Add a directive to your JSP script identifying the name of the file to call when an exception occurs.

    2. Create an appropriate "error page", optionally using the Exception object to obtain greater detail about the exception.

    Let's illustrate this process with a simple example. Here's a JSP script that divides a number by zero - a process guaranteed to make any programming language scream in anguish.

    <% int a = 19; int b = 0; int c = a/b; %>

    Here's the output:

    Error: 500 Internal Servlet Error: javax.servlet.ServletException: / by zero at org.apache.jasper.runtime.PageContextImpl.handlePageException (PageContextImpl.java:459) at _0002fb_0002ejspb_jsp_2._jspService(_0002fb_0002ejspb_jsp_2.java:72) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service (JspServlet.java:177) at org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:318) at org.apache.jasper.servlet.JspServlet.service (JspServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404) at org.apache.tomcat.core.Handler.service(Handler.java:286) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79 7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743) at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection (Ajp12ConnectionHandler.java:166) at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java, Compiled Code) at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java, Compiled Code) at java.lang.Thread.run(Thread.java, Compiled Code) Root cause: java.lang.ArithmeticException: / by zero at _0002fb_0002ejspb_jsp_2._jspService(_0002fb_0002ejspb_jsp_2.java:62) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja va:177) at org.apache.jasper.servlet.JspServlet.serviceJspFil(JspServlet.java:318) at org.apache.jasper.servlet.JspServlet.service (JspServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService (ServletWrapper.java:404) at org.apache.tomcat.core.Handler.service(Handler.java:286) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79 7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743) at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection (Ajp12ConnectionHandler.java:166) at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java, Compiled Code) at org.apache.tomcat.util.ThreadPool$ControlRunnable.run (ThreadPool.java, Compiled Code) at java.lang.Thread.run(Thread.java, Compiled Code)

    Ugly, huh?

    In order to have this exception handled by JSP, so that the user never has to see something so ugly, you need to simply add a

    <%@ page errorPage="error.jsp" %>

    to the script, so that it looks like this:

    <% int a = 19; int b = 0; int c = a/b; %>

    An exception thrown by the script will now be caught by JSP, and automatically routed to "error.jsp". Let's look at that next.

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


     

       

    JAVA ARTICLES

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway