【发布时间】:2014-04-06 15:29:27
【问题描述】:
我正在为我在 tomcat 7 上运行的 JSP 应用程序创建一个简单的自定义错误页面。我在打印异常时遇到问题。打印时的异常变量:
<%= exception %>
始终为空。
web.xml
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
error.jsp
<%@ page isErrorPage="true" import="java.io.*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Error Page</title>
</head>
<body>
<div>
<h3>Error</h3>
<h4><b>Exception:</b><br></h4>
<p><i><%= exception %></i><p>
</div>
<footer></footer>
</body>
指令
我还加了:
<%@ page errorPage="errorPage.jsp" %>
到我的所有页面。
错误
当它运行时,它只会为异常变量打印 null。如果我尝试将其更改为
exception.printStackTrace(response.getWriter()
我会收到如下所示的错误:
SEVERE: Exception Processing ErrorPage[errorCode=404, location=/error.jsp]
org.apache.jasper.JasperException: /error.jsp (line: 1, column: 32) equal symbol expected
【问题讨论】: