|
The second way is to define the error page in the page directive as "<%@ page errorPage="errorpage.jsp" %>" and creating the error page. When any exception or error occurs while processing the JSP page then the container automatically calls the error page and redirects the flow to it. Any page can be used to show the errors.Users have to set the ErrorPage="true" property on the page directive for example:-<%@ page isErrorPage="true" %> for error pages. While processing an error page an implicit object named "exception" automatically created for the page, which is used to display the error messages.
The below example will demonstrate the exception handling in the JSP and use of exception implicit object.
Exceptionhandling.jsp
<%@ page errorPage="errorpage.jsp" %> <%
String s=null; s.toString();
%>
errorpage.jsp
<%@ page isErrorPage="true" %>
This is the Error page.The following error occurs:- <br> <%= exception.toString() %>
Output:-
|