473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 14307
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

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

Similar topics

4
by: Eric West | last post by:
Greetings- I have a web application that has a form that triggers a server process that I would like to provide a "Searching..." page for. My strategy was to send the browser the "top half" of...
0
by: Naresh Agarwal | last post by:
Hi I want HTTPServletResponse to *close* the socket after sending the response. For this I'm closing the OutputStream after writing the data. But still socket is not closed and client keeps on...
1
by: Java script Dude | last post by:
I am investigating a solution to build all pages sent from my application servlet in UTF-8 encoding. From what I understand, I should be using HttpServletResponse.setCharacterEncoding("UTF-8"). The...
6
by: Nick Horrocks | last post by:
I have set up a custom error page for 404 errors. However the HTTP status code returned is 302 followed by 200, this causes search engines not to remove old pages from their index. How can I...
0
by: DT | last post by:
I'm writing a .NET 1.1 client that invokes a method of a Web Service running on another organization's IIS 5 server. I need help understanding a fine point about HTTP, specifically in relation to...
2
by: inferno2000 | last post by:
Let's say if I want to send a http "Post" request to a url, and check the http status code later. How should I write the code? I have found example to use WinHttp to send "Get" request and check...
1
by: sergiotb | last post by:
Hello everyone!! I'm trying to send a image (jpg) from a C# program to a CGI perl. The problem is that the code of the client C# is not working properly...I guess. The steps to send the image are: 1)...
2
by: Khai Doan | last post by:
I am using Selenium, a javascript framework for automated testing of web application. The problem occurs when there is a server side HTTP redirect. Selenium would detect that a new page is...
2
by: xinariscy | last post by:
Hello everyone! I have a webpage with a form with two text boxes and the action of the form it's a servlet. I know how to get the HttpServletResponse response from a servlet like this: .......
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.