To handle the JSP errors, lets have a look of the different types of errors first. There are two types of errors in JSP:
1) Translation Time Errors and 2) Request Time Errors
Translation Time Errors
These errors occur when a JSP is first requested and goes through the initial translation from a JSP source file into a corresponding Servlet class file. (Read more about JSP Life Cycle in this post)
They are reported to the requested client with an error status code 500 or ‘server error’. They usually contain the reported compilation error. These errors are handled by the JSP Engine.
Request Time Errors
These errors are runtime errors that can occur in either the body of the JSP page or in some other object that is called from the body of the JSP page.
These result in an exception being thrown. These exceptions can be caught and approximately handled in the body of the calling JSP, which would be the end of the error.
Those exceptions not caught result in the forwarding of the client request, including uncaught exception, to the error page specified by the offending JSP.
Handling The Errors
To handle the errors in jsp, we need to create a JSP error page and use it in the JSP. So lets see how can we do that:
Creating a JSP Error Page:
For creating an error page, create a basic JSP page and then you need to tell the JSP engine that the page is an Error Page. Simple by setting its page attribute “isErrorPage” to true.
Using a JSP Error Page
In the JSP, add 1 additional attribute, in your page directive, to make JSP aware of an error page. Add ‘errorpage’ attribute and set its value equal to the location of your JSP error page.