0

I'm sending a custom error page for 404 in jsp. But I want to know if it is possible to add attributes to page, as request dispatcher does it.

I have a user session to bar with some information, like its name, and other things, and I want to that page contains the same top bar. It is possible in this way of sending error pages?

Thanks.

wilmerlpr
  • 448
  • 6
  • 15

1 Answers1

0

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>
thst
  • 4,592
  • 1
  • 26
  • 40