Custom, minimal error page

This commit is contained in:
Sean Owen 2014-01-22 21:11:55 +00:00
parent 62cf0ade90
commit a8772054af
2 changed files with 56 additions and 0 deletions

View file

@ -60,4 +60,8 @@
<welcome-file>index.jspx</welcome-file>
</welcome-file-list>
<error-page>
<location>/error.jspx</location>
</error-page>
</web-app>

View file

@ -0,0 +1,52 @@
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
<!--
Copyright 2008 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<jsp:directive.page contentType="text/html" isErrorPage="true" session="false"/>
<jsp:directive.page import="
java.io.PrintWriter,
java.io.StringWriter,
com.google.common.xml.XmlEscapers"/>
<jsp:text><![CDATA[<!DOCTYPE html>]]></jsp:text>
<html>
<head>
<title>Error</title>
<style type="text/css">body{background-color:#e9eef3}</style>
</head>
<body>
<p><strong>Error ${pageContext.errorData.statusCode}</strong> : ${pageContext.errorData.requestURI}</p>
<jsp:scriptlet>
if (request.getAttribute("javax.servlet.error.message") != null) {
String responseMessage = request.getAttribute("javax.servlet.error.message").toString();
pageContext.setAttribute("responseMessage", XmlEscapers.xmlContentEscaper().escape(responseMessage));
</jsp:scriptlet>
<p><strong>${responseMessage}</strong></p>
<jsp:scriptlet>
}
</jsp:scriptlet>
<jsp:scriptlet>
Throwable t = pageContext.getErrorData().getThrowable();
if (t != null) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
pageContext.setAttribute("stackTrace", XmlEscapers.xmlContentEscaper().escape(sw.toString()));
</jsp:scriptlet>
<p><pre>${stackTrace}</pre></p>
<jsp:scriptlet>
}
</jsp:scriptlet>
</body>
</html>
</jsp:root>