471,829 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,829 software developers and data experts.

HttpServletResponse to get Http Status Code

101 100+
Hi,

When we get request on server after processing that it writes back the response to client that also contains HTTP status code like 200 for Ok, 404 for page not found.

How can I have access to that in java, how can i retrieve that status code. Please help.
Nov 5 '08 #1
4 14152
JosAH
11,448 Expert 8TB
The Servlet itself (or any other class in charge) sets that status code itself; there
is no reason to retrieve it again from the response object, they can remember
that themselves if they want to. Why do you need that (redundant) functionality?
Any practical purpose?

kind regards,

Jos
Nov 5 '08 #2
buntyindia
101 100+
The Servlet itself (or any other class in charge) sets that status code itself; there
is no reason to retrieve it again from the response object, they can remember
that themselves if they want to. Why do you need that (redundant) functionality?
Any practical purpose?

kind regards,

Jos
Before setting that status I want to know the status so that on this basis of the code I can perform certain functionality.

I am using Filters for logging different kind of logs in this I need to know what is the status of HTTP response.
Nov 6 '08 #3
itsraghz
127 100+
How about looking at the
Expand|Select|Wrap|Line Numbers
  1. <error-code>
and
Expand|Select|Wrap|Line Numbers
  1. <error-page>
elements in web.xml?
Nov 6 '08 #4
You may obtain the http status line with the following code:

httpStatusLine = urlConnection.getHeaderFields().get(null).get(0);

Having this status, you just have to extract the status code :

static final Pattern HTTP_STATUS_CODE_PATTERN=Pattern.compile("(\\d{3}) ");
Matcher matcher = HTTP_STATUS_CODE_PATTERN.matcher(httpStatusLine);
if (matcher.find()){
httpCode = matcher.group(1);
}


Regards,

André
Dec 23 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Eric West | last post: by
reply views Thread by Naresh Agarwal | last post: by
1 post views Thread by Java script Dude | last post: by
6 posts views Thread by Nick Horrocks | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.