Chapter 6. Generating the Server Response: HTTP Status Codes

Topics in This Chapter

  • Format of the HTTP response

  • How to set status codes

  • What the status codes are good for

  • Shortcut methods for redirection and error pages

  • A servlet that redirects users to browser-specific pages

  • A front end to various search engines

As we saw in the previous chapter, a request from a browser or other client consists of an HTTP command (usually GET or POST), zero or more request headers (one or more in HTTP 1.1, since Host is required), a blank line, and, only in the case of POST requests, some query data. A typical request looks like the following.

GET /servlet/SomeName HTTP/1.1
Host: ...
Header2: ...
...
HeaderN:
  (Blank Line)

When a Web server responds to a request, the ...

Get Core Servlets and JavaServer Pages™: Volume 1: Core Technologies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.