This feature of HTML Channel controls the errors and exceptions that have not been managed by the operations.
In the server-side toolkit configuration file (btt.xml), under the HtmlClient keyed collection, the attribute errorPage is the name of a JSP that is displayed when a system exception occurs. When this page is displayed by the presentation handler, the exception itself will be saved in the request under the key name "exception" (actually the key name is saved symbolically as com.ibm.btt.cs.html.HtmlConstants.EXCEPTION). The JSP can use the JSP Context Services bean to check for errors that were detected during the data validation process. The JSP can then retrieve and manage the specific data field error.
Normally, the exceptions are caught by the BTT channels. BTT channels would put these exceptions into the attributes of "request.getAttribute(HtmlConstants.EXCEPTION)". So you could get the exception object through the key word "dse_exception" which is the value of "HtmlConstants.Exception".
But in some situations when BTT are not capable of catching some errors or exceptions, these will be thrown into the http server or web server. For this kind of exceptions, the "request.getAttribute(HtmlConstants.EXCEPTION)" will return null. It will return the error code like 404 and 500.
<error-page> <error-code>404</error-code> <location>/jsp/errorpage.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/jsp/errorpage.jsp</location> </error-page> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/jsp/errorpage.jsp</location> </error-page
Error
Code:<%=request.getAttribute("javax.servlet.error.status_code")%> <br>
Info
: <%=request.getAttribute("javax.servlet.error.message")%> <br>
Exception
: <%=request.getAttribute("javax.servlet.error.exception_type")%> <br>
if(null != exception){ out.println("An exception was thrown:" + exception.getClass()); out.println("Exception message:"); out.println(exception.getMessage()); out.println("Exception stack trace:"); exception.printStackTrace(); ByteArrayOutputStream ostr = new ByteArrayOutputStream(); exception.printStackTrace(new PrintStream(ostr)); out.print(ostr); }
<%@page import="com.ibm.btt.base.FunctionalErrorTraceHelper"%> <%@page import="com.ibm.btt.cs.html.HtmlConstants"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <<DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Error Page</title> </head> <body> <tt style="color: red"> An internal error has occurred. Please review the traces. <% if (null != request.getAttribute(HtmlConstants.EXCEPTION)) { Exception e = (Exception) request .getAttribute(HtmlConstants.EXCEPTION); StringBuffer sb = new StringBuffer(); sb.append("<hr/>"); sb.append("Detailed exception message is:<br/>"); if (null != e.getMessage()) { sb.append(e.getMessage().replaceAll("<","< ">.replaceAll(">"," >")); } out.println(sb.toString()); // Show additional info if possible String[] msgs = FunctionalErrorTraceHelper.getMessagesForException(e); if (msgs.length > 0) { out.println("<br/><br/>Additional error information:<br/>"); for (String msg : msgs) { out.println(" " + msg + "<br/>"); } } } else if (null != request.getAttribute("javax.servlet.error.status_code")) { out.println("<br/>"); out.println("Error Code: " + request.getAttribute("javax.servlet.error.status_code") + "<br/>"); out.println("Error Info : " + request.getAttribute("javax.servlet.error.message") + "<br/>"); out.println("Exception : " + request.getAttribute("javax.servlet.error.exception_type") + "<br/>"); } %> </tt> </body> </html>