我有一个servlet进行一些错误检查,如果出现问题,我通常会这样做:
response.sendError(403, "My message")
return;
Run Code Online (Sandbox Code Playgroud)
我不希望从servlet抛出一个异常-因为我想用HTTP状态代码一致.
在web.xml中我配置了以下内容:
<error-page>
<error-code>403</error-code>
<location>/failure.jsp</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
在failure.jsp中我声明了JSTL的用法,我希望显示错误消息.我知道我可以在scriptlet中执行以下操作:
<%= request.getAttribute("javax.servlet.error.message") %>
但我想使用JSTL和一些c:if子句,所以如果我可以使用scriptlet,这将是值得赞赏的.
如何使用JSTL轻松从错误页面中的servlet中的sendError语句中获取值?