Chapter 7. Generating the Server Response: HTTP Response Headers

Chapter 7. Generating the Server Response: HTTP Response Headers

Topics in This Chapter

  • Format of the HTTP response

  • Setting response headers

  • Understanding what response headers are good for

  • Building Excel spread sheets

  • Generating JPEG images dynamically

  • Sending incremental updates to the browser

As discussed in the previous chapter, a response from a Web server normally consists of a status line, one or more response headers (one of which must be Content-Type ), a blank line, and the document. To get the most out of your servlets, you need to know how to use the status line and response headers effectively, not just how to generate the document.

Setting the HTTP response headers often goes hand in hand with setting the status codes in the status line, as discussed in the previous chapter. For example, all the "document moved" status codes (300 through 307) have an accompanying Location header, and a 401 ( Unauthorized ) code always includes an accompanying WWW-Authenticate header. However, specifying headers can also play a useful role even when no unusual status code is set. Response headers can be used to specify cookies, to supply the page modification date (for client-side caching), to instruct the browser to reload the page after a designated interval, to give the file size so that persistent HTTP connections can be used, to designate the type of document being generated, and to perform many other tasks . This chapter shows how to generate response headers, explains what the various headers are used for, and gives several examples.



Core Servlets and JavaServer Pages (Vol. 1.Core Technologies)
Core Servlets and Javaserver Pages: Core Technologies, Vol. 1 (2nd Edition)
ISBN: 0130092290
EAN: 2147483647
Year: 2002
Pages: 194

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net