JSP Error Page
JSP Error Page is used to specify the custom error page and runtime error occurs with an exception being thrown, the custom error page helps in handling the error page and display a customized view of the exception.
Understand with Example
In this section, you will learn the use of errorPage attribute of the page
directive in jsp. This attribute sets a url and if any exception is generated it
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.
Here we have used two jsp pages:
In the error.jsp page, we have initialized a string variable to null in a scriplet and use the method st.length() inorder to determine the length of the string which is the cause of generating an error. This page is redirected to the errorPage.jsp as specified in the errorPage attribute of the page directive. The page errorPage.jsp shows the error generated in calling the JSP page by setting the isErrorPage attribute to true.
Here is the code of error.jsp
Here is the code of errorPage.jsp
Output will be displayed as: