JSP Exception Implicit Object

In this tutorial you will learn about the JSP Exception Implicit Object and its application with practical example.

JSP Exception Implicit Object

The exception object describing the error is a java.lang.Exception instance that is accessible in the error page through the implicit exception object. Only an error page can access the implicit exception object. When the error condition occurred so this implicit object is used to generate an appropriate response. In other words Exception is normally an object which is thrown at runtime, With the help of Exception Handling we can handle runtime process.
In JSP we can perform exception handling by two way:

Table Of Contents

#Page Directive: With the help of this you can simply create an jsp page and call as directive tag in your processing page.

#By specifying the error-page element in web.xml: If you use this approach for handling error so you do not need to call page directives on each jsp, because you have declared in web.xml file, like below code.

Example: Let’s try exception handling using “errorPage an isErrorPage attributes of page directive“.First we need to create jsp page for an exception.

1.exception.jsp: This page will called when an exception will occurred. Check out below code.

2.index.jsp: This page will appear when you will run, from here you have to enter numbers so that you can divide, check below code.

Output: The above code output will look like below image.


#processingPage.jsp: This page will do process of division and if any exception occurred so exception.jsp page will appear with the help of <%@ page errorPage=”exception.jsp” %> this directive tag. Check below code.

Output: The output of above code differs according to your input, if any exception occurred so output will be “Error Page” else answer of given input will shown. Check below images.





Example: In this example we will learn that how we can declare our exception page in web.xml file. You do not need to call your page again and again for each jsp, it will automatically called by web.xml. Check below code, exception.jsp and index.jsp page are same as I used in above example, now need to check our processingPage.jsp file and web.xml file.


#web.xml: From here we will declare our exception.jsp page like below code.

#processingPage.jsp: Just remove your directive tag from last processingPage.jsp because we have declare our exception.jsp page in web.xml or check below code.

#Output: It will be like our first example because we did not change our exception.jsp page.


In this tutorial we have learn about the JSP Exception Implicit Object and its application with practical example. I hope you will like this tutorial.