【发布时间】:2012-03-09 20:26:35
【问题描述】:
我注册了一个错误页面:
<error-page>
<error-code>401</error-code>
<location>/WEB-INF/exceptions/401.jsp</location>
</error-page>
我在我的 Servlet 中触发了一个错误:
response.sendError(401, "message here");
401.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
...
<body>
<h1>Unauthorized (401)</h1>
<p><%= exception.getMessage() %></p>
</body>
</html>
很遗憾,仅显示“通用”401 页面。
我已经重新启动了应用程序和 Tomcat,但没有任何变化。
我错过了什么?
** 编辑 0 **
我包含了 JSP 文件的代码。
看来问题出在<%= exception.getMessage() %> 代码上。如果将其删除,自定义页面将按预期显示。如果存在,则会显示“通用”消息。
我替换了这个 JSTL ${pageContext.errorData.throwable.message}。显示自定义 401 页面,但消息为空白。
【问题讨论】:
-
已解决:[从 JSTL 显示 httpServletResponse.sendError(403, “My Message”) 状态的最简单方法是什么][1] [1]: stackoverflow.com/questions/1104452/…