Share on Google+Share on Google+

JSP Error Page

This page discusses - JSP Error Page

JSP Error Page


JSP Error Page is used to specify the custom error page and runtime error occurs with an exception being thrown, the custom error page helps in handling the error page and display a customized view of the exception.

Understand with Example

In this section, you will learn the use of errorPage attribute of the page directive in jsp. This attribute sets a url and if any exception is generated it refers to the file which is mentioned in the given url. If you do not specify the url then the attribute refers to the current page of your JSP application. Here we have used two jsp pages:
1) error.jsp
2) errorPage.jsp

In the error.jsp page, we have initialized a string variable to null in a scriplet and use the method st.length() inorder to determine the length of the string which is the  cause of generating an error. This page is redirected to the errorPage.jsp as specified in the errorPage attribute of the page directive. The page errorPage.jsp shows the error generated in calling the JSP page by setting the isErrorPage attribute to true.

Here is the code of error.jsp

<[email protected] errorPage="errorPage.jsp" %>
<head><title>Error Page</title></head>
String st = null;
The length of the string is <%= st.length() %>

Here is the code of errorPage.jsp

<%@ page isErrorPage="true" import="*" %>
<h2>Error Encountered!</h2>
<font color="red"><%= exception %> has been encountered. You haven't specify any String.</font>

Output will be displayed as:

Download Source Code:


Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JSP Error Page  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image