我如何从HttpServletResponse.sendError检索msg [英] how can i retrieve the msg from HttpServletResponse.sendError

查看:662
本文介绍了我如何从HttpServletResponse.sendError检索msg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台Tomcat服务器之间进行通信。在其中一个服务器发生错误时,我想向其他服务器发送错误响应。



我使用以下方式发送错误:
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆