我如何从HttpServletResponse.sendError检索msg [英] how can i retrieve the msg from HttpServletResponse.sendError
问题描述
我使用以下方式发送错误:
resp.sendError (HttpServletResponse.SC_BAD_REQUEST,e.getMessage());
我使用org.apache.commons.httpclient.httpMethod捕获响应。
我的问题是如何检索我添加到错误消息的e.getMessage()?
谢谢
您可以通过在web.xml中声明状态代码的特定页面来覆盖发送的页面:
< error-page>
< error-code> 400< / error-code>
< location> /errorMsg.jsp< / location>
< / error-page>
在JSP中,执行以下操作:
<%@ page isErrorPage =true%>
<%= exception.getMessage(); %GT;
然后,所有发回的都是消息。
i have two tomcat servers that communicate between them. upon an error at one of the servers i would like to send an error response to the other server.
i am sending the error using: resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
i am catching the response with org.apache.commons.httpclient.httpMethod.
my question is how can i retrieve the e.getMessage () that i am adding to the error message?
thanks
You can override the page that is sent by declaring a specific page for the status code in the web.xml:
<error-page>
<error-code>400</error-code>
<location>/errorMsg.jsp</location>
</error-page>
In the JSP, do something like:
<%@page isErrorPage="true"%>
<%= exception.getMessage(); %>
Then, all that is sent back is the message.
这篇关于我如何从HttpServletResponse.sendError检索msg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!