473,378 Members | 1,470 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,378 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 14319
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: .......
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.