Skip to main content

HTTP Status Codes

In a web app, whenever there is a communication between the browser (i.e client) and (web) server, there is a back-and-forth transfer of data. The client sends data to Server for processing. Data is then processed at the server side, and a response is sent back to client, indicating the status of the sent request. The response sent by Server to browser, typically, has a status line, some response headers, blank line, and the document, e.g.

HTTP/1.1 200 OK
Content-Type: text/plain

This is an example of status codes.

Here, the first line indicates the HTTP Version (HTTP/1.1), a status code (200) and a short description of status code (ok). Second line consists of the various headers sent by Server. At mimimal, it has a content type. The data after the blank line indicates the document itself, though not all responses may have a document. If a document is present, the content type indicates its MIME type.

Given below is a list of the commonly used status codes. The status codes are all three-digit numbers that are grouped by the first digit into 5 groups.

1xx: Informational

100 Continue
Continue with partial request.

101 Switching Protocols
Server will comply with Upgrade header and change to different protocol.


2xx: Successful

200 OK
Means that the server did whatever the client wanted it to, and all is well.

Others
The rest of the 2xx status codes are mainly meant for script processing and are
not often used.


3xx: Redirection
Means that the resource is somewhere else and that the client should try again at
a new address.

301 Moved permanently
The resource the client requested is somewhere else, and the client should go there
to get it. Any links or other references to this resource should be updated.

302 Moved temporarily
This means the same as the 301 response, but links should now not be updated, since
the resource may be moved again in the future.

304 Not modified
This response can be returned if the client used the if-modified-since header field
and the resource has not been modified since the given time. Simply means that the
cached version should be displayed for the user.


4xx: Client error
Means that the client screwed up somehow, usually by asking for something it should
not have asked for.

400 Bad request
The request sent by the client didn't have the correct syntax.

401 Unauthorized
Client tried to access password-protected page without proper authorization. Response should include a WWW-Authenticate header that the browser would use to pop up a username/password dialog box, which then comes back via the Authorization header.

403 Forbidden
The client is not allowed to access the resource and authorization will not help.
Often the result of bad file or directory permissions on the server.

404 Not found
Seen this one before? :) It means that the server has not heard of the resource
and has no further clues as to what the client should do about it. In simpler
words: dead link.

405 Method Not Allowed
The request method not allowed for this particular resource.


5xx: Server error
This means that the server screwed up or that it couldn't do as the client requested.

500 Internal server error
Something went wrong inside the server. It is often the result of Servlets or CGI
programs or (Any Other Server Side Technology) that crash or return improperly
formatted headers.

501 Not implemented
The request method is not supported by the server.

503 Service unavailable
This sometimes happens if the server is too heavily loaded and cannot service the
request. Usually, the solution is for the client to wait a while and try again.
A servlet might return this header if some thread or database connection pool is
currently full. Server can supply a Retry-After header.

505 HTTP Version Not Supported
Server doesn't support version of HTTP indicated in request line.


Just keep in mind that some of the status codes may be available only in HTTP/1.1 version though some of the browsers may still support only HTTP/1.0 version.
The general method of setting status codes is simply to call response.setStatus(int), there are two common cases where a shortcut method in HttpServletResponse is provided. The sendError method generates a 404 response along with a short message formatted inside an HTML document. The advantage of sendError over setStatus is that, with sendError, the server automatically generates an error page showing the error message. And the sendRedirect method generates a 302 response along with a Location header indicating the URL of the new document.


Advertisement
Fund Literacy, Care for the Environment, and get a Fair Price on the Books you Want.
http://www.betterworld.com/

Comments

Popular posts from this blog

Installing Bugzilla on Windows

Bugzilla is the Bugs/Issues Tracking Tool from The Mozilla Organization. Version 2.18 is the latest stable release. There are couple of resources which guide a User installing Bugzilla on a Unix/linux machine. However, this entry describes a way to install Bugzilla on a Windows machine (W2K to be precise). This document guides you step by step through the installation process. First, get Administrative access to the machine on which you want to install Bugzilla. It should be a simple step. Usually, Users are given Administrative rights on Windows machine. However, if you dont have, contact your Administrator. Get Bugzilla Then download the Bugzilla from http://bugzilla.org/download.html . There are two ways of gettng it - through CVS or direct downloading the tar file. Remember there are no Zip files. However, any zip utility should be able to untar the Bugzilla. I download the tar file and untarred it using WinZip. I placed the untarred 'bugzilla' directory in my c: drive. So...

Online Hindi Radio Stations

Here is the list of Online Hindi Radio Stations. Copy the URL in your media player and enjoy !! 106.2 HUMFM - UAE ==> http://www.humfm.com/humfm.asx AajKal - Asian Network ==> http://stream.servstream.com/ViewWeb/BBCRadio_music/Event/BBCAsianNetwork_hi.asx Amrit Bani - UK ==> http://62.25.97.192/amritbani?MSWMExt=.asf ApnaRadio - USA ==> http://www.apnaradio.com/live/media24/ApnaRadio.asx Asian Gold Radio - UK ==> http://62.25.96.7/asiangold Asian Sound Radio - UK ==> http://www.vtuner.com/vtunerweb/mms/mms15278.asx BBC News ==> http://www.bbc.co.uk/worldservice/meta/tx/nb/live_news_au_nb.asx BombayBeats FM ==> http://www.1.fm/player/energybbfm32k.asx City 101.6 FM - Dubai ==> http://asx.abacast.com/arabian_radio-city-24.asx DDLive Video - India ==> http://164.100.51.209/ddlive?MSWMExt=.asf DesiSoundz - India ==> http://desisoundz.com:8000 Haagstad Radio - Holand ==> mms://81.205.146.32:21/haagstadradio kismatradio.com ==> http://www.kismatradio....

What are the different type of JDBC drivers?

There are four types of JDBC database driver: The JDBC/ODBC bridge driver (Type 1) A piece of native C-code that translates a JDBC call to an ODBC call. Use this driver for development, not for industrial-strength application environments. Note that you have to have an ODBC database driver manager + an ODBC database driver installed on the server in addition to the JDBC/ODBC bridge. Though useful for learning JDBC and quick testing, bridging solutions are rarely appropriate for production environments. Native API partly java driver (Type 2) A piece of native C-code that translates a java JDBC call to a native database call level API. Use this driver for development and deployment. Due to its native code, this driver can only be used by Java Applications with full computer access (i.e. not Applets). Type 2 drivers generally provide the best performance, but they require the installation of native libraries on clients that need to access the database. Applications using Type 2 drivers ...