Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
126
Chapter 6 Generating the Server Response: HTTP Status Codes
6.2 HTTP 1.1 Status Codes and
Their Purpose
The following sections describe each of the status codes available for use in
servlets talking to HTTP 1.1 clients, along with the standard message associ
ated with each code. A good understanding of these codes can dramatically
increase the capabilities of your servlets, so you should at least skim the
descriptions to see what options are at your disposal. You can come back to
get details when you are ready to make use of some of the capabilities. Note
that Appendix A (Servlet and JSP Quick Reference) presents a brief summary
of these codes in tabular format.
The complete HTTP 1.1 specification is given in RFC 2616, which you can
access on line by going to
http://www.rfc editor.org/
and following the
links to the latest RFC archive sites. Codes that are new in HTTP 1.1 are
noted, since many browsers support only HTTP 1.0. You should only send
the new codes to clients that support HTTP 1.1, as verified by checking
request.getRequestProtocol
.
The rest of this section describes the specific status codes available in
HTTP 1.1. These codes fall into five general categories:
100 199
Codes in the 100s are informational, indicating that the client
should respond with some other action.
200 299
Values in the 200s signify that the request was successful.
300 399
Values in the 300s are used for files that have moved and usually
include a
Location
header indicating the new address.
400 499
Values in the 400s indicate an error by the client.
500 599
Codes in the 500s signify an error by the server.
The constants in
HttpServletResponse
that represent the various codes
are derived from the standard messages associated with the codes. In serv
lets, you usually refer to status codes only by means of these constants. For
example, you would use
response.setSta
tus(response.SC_NO_CONTENT)
rather than
response.setStatus(204)
,
since the latter is unclear to readers and is prone to typographical errors.
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved