Share on Google+Share on Google+

Page Directive attribute - errorPage

This tutorial contains description of errorPage attribute of page Directive.

Page Directive attribute - errorPage

This tutorial  contains description of errorPage attribute of page Directive.

errorPage Attribute :

Functionality of errorPage attribute is to define the error page. If there is exception then the JSP page is redirected to the error page. You can set url that is relative path of the error page. If there is any exception this attribute refers towards the file mentioned in the given url. If you didn't specified any url then this attribute refers to the current page at the time exception occurred.

Syntax :

<%@page errorPage="relativeURL" %>

Example : In this example, errorPageAttribute.jsp is our jsp page. When we click on button the errorPage.jsp is opened and the exception is displayed on that page.


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


<form method="post">
<td>Enter a number:</td>
<td><input type="text" name="num" />
<td><input type="submit" name="submit" value="Divide by zero" />

if (request.getParameter("num") != null) {
if (!request.getParameter("num").equals("")) {
int div = Integer.parseInt(request.getParameter("num")) / 0;
out.println("Answer is: " + div);

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



<%@page isErrorPage="true" %>


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

<body >

<font><b>Your page generated an error:<br/>


<%= exception.toString() %>



Output :


Posted on: November 28, 2012 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.