How to create a common error page using JSP?

JSP gives you an option to specify Error Page for each JSP using page attribute. Whenever the page throws an exception, the JSP container automatically invokes the error page.

Following is an example to specifiy an error page for a main.jsp. To set up an error page, use the directive.



   
      Error Handling Example
   
   
      
   

We will now write one Error Handling JSP ShowError.jsp, which is given below. Notice that the error-handling page includes the directive . This directive causes the JSP compiler to generate the exception instance variable.



   
      Show Error Page
   
   
      

Opps...

Sorry, an error occurred.

Here is the exception stack trace:


   

Access the main.jsp, you will receive an output somewhat like the following ?

java.lang.RuntimeException: Error condition!!!
......

Opps...
Sorry, an error occurred.

Here is the exception stack trace:
Updated on: 2019-07-30T22:30:25+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements