You can define custom error pages in your web.xml
and you can access the session in the error-page code.
<error-page>
<error-code>400</error-code>
<location>/WEB-INF/jsp/errorpages/ErrorPage400.jsp</location>
</error-page>
web.xml
is described fully here: http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/web_xml.html
Look at documentation from oracle here: https://docs.oracle.com/cd/E19316-01/819-3669/bnahi/index.html
For example, the error page for Duke’s Bookstore is as follows:
<%@ page isErrorPage="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>
<html>
<head>
<title><fmt:message key="ServerError"/></title>
</head>
<body bgcolor="white">
<h3>
<fmt:message key="ServerError"/>
</h3>
<p>
: ${pageContext.errorData.throwable.cause}
</body>
</html>