从JSTL显示httpServletResponse.sendError(403,“我的消息”)状态的最简单的方法是什么 [英] What is the simplest way to display httpServletResponse.sendError(403, "My Message") status from JSTL
问题描述
response.sendError(403,我的消息)
return;
我不要想从servlet中抛出异常 - 因为我想符合HTTP状态代码。
在web.xml中,我已经配置了以下内容:
< error-page>
< error-code> 403< / error-code>
< location> /failure.jsp< / location>
< / error-page>
在failure.jsp中我已声明使用JSTL,我想得到显示的错误信息。我知道我可以在scriptlet中执行以下操作:
<%= request.getAttribute(javax.servlet.error.message )%>
但是我想使用JSTL与一些c:if子句,所以如果我可以删除使用scriptlet,这将不胜感激。 p>
如何使用JSTL轻松地从错误页面的servlet中的sendError语句中获取值?
该scriptlet:
<%= request.getAttribute(javax.servlet。 error.message)%>
可以翻译成以下EL:
$ {requestScope ['javax.servlet.error.message']}
如果您在地图中有点,则支架符号
bean ['foo.bar']
非常有用>或作用域名称,因为 bean.foo.bar
显然不会返回所需的 Map
或范围值。
I have a servlet which does some error checking and if something is wrong I will typically do this:
response.sendError(403, "My message")
return;
I don't want to throw an exception from the servlet - because I would like to conform with HTTP status codes.
In the web.xml I have configured the following:
<error-page>
<error-code>403</error-code>
<location>/failure.jsp</location>
</error-page>
In the failure.jsp I have declared usage of JSTL and I would like to get the error messages displayed. I know that I can do the following in scriptlets:
<%= request.getAttribute("javax.servlet.error.message") %>
But I would like to use JSTL with some c:if clause so if I can drop using scriptlets, this would be appreciated.
How can I easily fetch the values from the sendError statement in the servlet in the error page by using JSTL?
The scriptlet:
<%= request.getAttribute("javax.servlet.error.message") %>
can be translated to the following EL:
${requestScope['javax.servlet.error.message']}
The brace notation bean['foo.bar']
is very useful if you have dots in Map
or scoped key names, because bean.foo.bar
obviously doesn't return the desired Map
or scoped value.
这篇关于从JSTL显示httpServletResponse.sendError(403,“我的消息”)状态的最简单的方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!