Page Directive attribute - isErrorPage


 

Page Directive attribute - isErrorPage

This tutorial contains description of isErrorPage attribute of page Directive.

This tutorial contains description of isErrorPage attribute of page Directive.

Page Directive attribute - isErrorPage

This tutorial  contains description of isErrorPage attribute of page Directive.

isErrorPage Attribute :

This attribute of page directives sets the boolean value either true or false. It represents whether or not the page is intended to be an error page of some other JSP page . Default value of the isErrorPage attribute is false. You can use the exception object in the JSP page if you set the true value of the attribute otherwise you cannot use the exception object because the default value of the attribute is false.

Syntax :

<%@ page isErrorPage="true" %>

Example :

errorPageAttribute.jsp

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

<html>

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

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

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

</html>

errorPage.jsp

<%@page isErrorPage="true" %>  //assigning true value to isErrorPage attribute.

<html>

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

<body >

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

Exception:<br/></b></font>

<%= exception.toString() %>

</body>

</html>

Output :



Ads