Advertisement



< Prev
Next >



JSP errorPage and isErrorPage Attribute






errorPage Attribute


In JSP, the errorPage attribute of page directive is used to specify a web page which will be displayed as an error page for the current JSP page i.e. if there is an error while executing the current page).




<%@ page errorPage= "path-to-another-jsp-page" %>





isErrorPage Attribute


In JSP, the isErrorPage attribute of page directive is used to specify whether the current page could be displayed as an error page for another JSP page. We could set the value of isErrorPage to either true or false.




By default, the isErrorPage attribute value is false, hence we don't have to set isErrorPage to false, in case if we don't want the current page to be displayed as an error appears for any JSP page.


Advertisement




errorPage and isErrorPage example


We are setting a web page ErrorPage.jsp as an error page for the current page StringLength.jsp

StringLength.jsp
<html>

<head>
<title>Calculate String Length</title>
</head>


<body>

<%
String str = null;
int length = str.length();
%>

Length of String is <%= length %>

</body>

</html>



ErrorPage.jsp
<html>

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


<body>

<%@ page isErrorPage= "true" %>
StringLength.jsp has reported an error :   <i> <%= exception %> </i>

</body>

</html>



executing the StringLength.jsp web page will throw an NullPointerException exception, which we read using JSP inbuilt exception object in ErrorPage.jsp.






Please share this article -




< Prev
Next >
< JSP info Attribute
JSP include Directive >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement