Share on Google+Share on Google+

The "errorPage" & "isErrorPage" Attribute of Page Directive

In this Section, we will discuss about the "errorPage" & "isErrorPage" attribute of Page Directive.

The "errorPage" & "isErrorPage"  Attribute of Page Directive

In this Section, we will discuss about the "errorPage" & "isErrorPage"  attribute of Page Directive.

The "errorPage" Attribute

When an unhandled Exception occurs in JSP page , the mentioned "errorpage" in this attribute is called. The syntax of this Page directive is as follows :

     <%@page errorPage="relativeURL" %>

"Relative Url" is the path of JSP file, who handled the exception. This attribute sets a url (relative path starting from the "/" , which refers to the root directory of your JSP application). If any exception is generated the the attribute 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 if any exception generated.

The "isErrorPage" attribute 

The Syntax of this page directive is :

     <%@page isErrorPage="true | false"  %> 

It is a Boolean attribute , if you set it's value "true" ,you can use "Exception" object in your JSP page otherwise you cannot use the exception object because the default value of the attribute is false .

Example :  

In this Example, we incorporate two JSP pages, one (errorpage.jsp)for entering data &  for implementing logic and second one(error.jsp) is for handling "Exception". If any exception occurs "error.jsp" page handles it & display the exception occurred.


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


<head><title>Showing Error Page.</title></head>


<form method="post">

<table border="0" cellspacing="0" cellpadding="0">


<td>Enter a number: </td>

<td><input type="text" name="txtNum" />




<td><input type="submit" name="B1" value="Divide by zero" />





if(request.getParameter("txtNum") != null){


int div = Integer.parseInt(request.getParameter("txtNum")) / 0;

out.println("Answer is: " + div);



out.println("<html><font color=red>Please enter a number.</font></html>");








<%@page isErrorPage="true" %>


<head><title>Error Page.</title></head>

<body bgcolor="blue">

<font size="5" color="white">Your page generated an error:"<br/>


<%= exception.toString() %>





After inputting number :

Download Source Code


Posted on: June 15, 2010 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.


Advertisement null