O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error pages get an extra object: exception

An error page is essentially the JSP that handles the exception, so the Container gives the page an extra object for the exception. You probably won’t want to show the exception to the user, but you’ve got it. In a scriptlet, you can use the implicit object exception, and from a JSP, you can use the EL implicit object ${pageContext.exception}. The object is type java.lang.Throwable, so in a script you can call methods, and with EL you can access the stackTrace and message properties.

A more explicit ERROR page (“errorPage.jsp”)

image with no caption

Note

Note: the exception implicit object is available ONLY to error pages with an explicitly-defined page directive: <%@ page isErrorPage=”true” %>

In other words, configuring an error page in the DD is not enough to make the Container give that page the implicit exception object!

What happens when you request “badPage.jsp”

image with no caption

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required