Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get a Servlet error message

843842Aug 7 2009 — edited Aug 7 2009
Hi all,

I have a servlet with this response:
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "No Access");
I want to connect this servelt with:
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
And read the error message, but just the custom String ("No Access"). Is it possible to obtain just this string?

I've tried with:
urlConn.getResponseMessage()
but i get the generic error message (Unauthorized) instead of the custom one.

With:
urlConn.getErrorStream();
I get the whole HTML error message generated by the server, so I'd had to parse it, which is not a good solution.

Any idea?

Thank you in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2009
Added on Aug 7 2009
4 comments
772 views