JDeveloper 10.1.3: JSP Error Page SupportJSP Error Page Support in JDeveloper 10.1.3 This
article explains how JDeveloper 10.1.3 provides support for creating
JSP error page, specifying error page on any JSP page, and JSP error
page template. In your web application file (JSP file/page), you can
specify an error page to take control of the exception handling for that page. If and when there is any uncaught exception from
the JSP file (when it's run), the Web Container catches that exception
and passes the exception to the error page specified in the JSP file
which threw that exception. The error page can display
information related to the cause of the exception/error to the user. Creating an Error PageAn
error page could be a JSP file with a marking which says that it's an error
page. The page directive has an attribute called 'isErrorPage'. This
attribute is set to true on an error page. ErrorPage.jsp <%@page isErrorPage=true %>
Now,
let's see how we can create an error page in JDeveloper. To create an
error page, do File->New->Web Tier->JSP->JSP This brings up the JSP file creation wizard. 
If
you take a look at the 'JSP File' page, it has three options related to
error page. The default option is, not to associate any error page with
the JSP file that is being created. Since we are creating this JSP file
as an error page, select the third option 'Create This File as an Error
Page'. Click 'Finish' and take a look at the code that is generated. What happens when 'Create this File as an Error Page' option is selected isErrorPage="true" attribute is set on the @page directive. This tells the web container that this file should be used as an error page. - A
template is created for the error message within the <body> tag. The
scriplet outputs the exception message and the exception stack trace to
the user
An error occured: <br></br> <pre> <% out.println(exception.getMessage()); CharArrayWriter charArrayWriter = new CharArrayWriter(); PrintWriter printWriter = new PrintWriter(charArrayWriter, true); exception.printStackTrace(printWriter); out.println(charArrayWriter.toString()); %> </pre>
You can edit the error page just like any other JSP page. How to Use the Error PageNow,
let's see how we can use the error page we have created. Create another
JSP file through File->New->Web Tier->JSP->JSP. For this
file, select the 'Use an Error Page to Handle Uncaught Exception in
This File' option in 'JSP File' page of the wizard. Click 'Next'. 
The
Wizard shows the 'Use Error Page' page which lists all the error pages
that are available in your web application. This page will not be shown,
if the 'Use an Error Page to Handle Uncaught Exception in This File'
option is not selected in 'JSP File' page of the Wizard. JDeveloper look
at all the JSP files to check whether isErrorPage is set; if so, list
the file name. Select an error page from the list and
click 'Finish'. What happens when you select an error page errorPage="/ErrorPage.jsp"
attribute is set on the page directive. This attribute tells the web
container that any uncaught exception in this page should be forwarded
to the error page with the name 'ErrorPage.jsp'. Note: Q: Instead of specifying error page on each of the JSP pages in a web application, is there a way to specify it globally? A: Yes. You can specify error page in web deployment descriptor file (web.xml) Q: Can a html file be used as an error page instead of a JSP page? A: Yes
11:45:45 AM
|