9.4. Using a Global Error Page

Problem

Your application should display the same error page for any server error or uncaught exception thrown from a Struts Action, a servlet, or a JSP page.

Solution

Declare a global error page, such as the one shown in Example 9-8, to handle all exceptions and errors in your web.xml file as well as your struts-config.xml file.

Example 9-8. Global JSP error page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@ page language="java" isErrorPage="true" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <html:html> <head> <title>Struts Cookbook Chapter 9 : Global error page</title> <style type="text/css"> h2{background:darkblue;color:white} h3{background:darkblue;color:white} </style> </head> <body> <div align="center"> <c:choose> <c:when test="${not empty pageContext.exception}"> <c:set var="problemType">JSP Exception</c:set> <c:set var="appException" value="${pageContext.exception}"/> <c:set var="causeException" value="${appException.cause}"/> </c:when> <c:when test="${not empty requestScope['javax.servlet. error.exception']}"> <c:set var="problemType">Servlet Exception</c:set> <c:set var="appException" value="${requestScope['javax. servlet.error.exception']}"/> ...

Get Jakarta Struts Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.