开发者

how can i retrieve the msg from HttpServletResponse.sendError

开发者 https://www.devze.com 2022-12-12 11:42 出处:网络
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 th开发者_JAVA技巧e other server.

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 th开发者_JAVA技巧e 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.


I think the error message gets packaged up in HTML and then sent, so in order to get the message you will need to parse the HTML.

I would suggest this isn't the most efficient way of transferring information between two servers. Provided that no humans need to look at the data, why don't you send the messages in a machine-readable format such as XML instead? Is there a specific reason you need to use response.sendError()?

0

精彩评论

暂无评论...
验证码 换一张
取 消