Chapter 5. Handling the Client Request: HTTP Request Headers

Chapter 5. Handling the Client Request: HTTP Request Headers

Topics in This Chapter

  • Reading HTTP request headers

  • Building a table of all the request headers

  • Understanding the various request headers

  • Reducing download times by compressing pages

  • Differentiating among types of browsers

  • Customizing pages according to how users got there

  • Accessing the standard CGI variables

One of the keys to creating effective servlets is understanding how to manipulate the HyperText Transfer Protocol (HTTP). Thoroughly understanding this protocol is not an esoteric, theoretical concept, but rather a practical issue that can have an immediate impact on the performance and usability of your servlets. This section discusses the HTTP information that is sent from the browser to the server in the form of request headers. It explains the most important HTTP 1.1 request headers, summarizing how and why they would be used in a servlet. As we see later, request headers are read and applied the same way in JSP pages as they are in servlets.

Note that HTTP request headers are distinct from the form (query) data discussed in the previous chapter. Form data results directly from user input and is sent as part of the URL for GET requests and on a separate line for POST requests. Request headers, on the other hand, are indirectly set by the browser and are sent immediately following the initial GET or POST request line. For instance, the following example shows an HTTP request that might result from a user submitting a book-search request to a servlet at http://www.somebookstore.com/servlet/Search . The request includes the headers Accept , Accept-Encoding , Connection , Cookie , Host , Referer , and User-Agent , all of which might be important to the operation of the servlet, but none of which can be derived from the form data or deduced automatically: the servlet needs to explicitly read the request headers to make use of this information.

 
 GET /servlet/Search?keywords=servlets+jsp HTTP/1.1  Accept  : image/gif, image/jpg, */*  Accept-Encoding  : gzip  Connection  : Keep-Alive  Cookie  : userID=id456578  Host  : www.somebookstore.com  Referer  : http://www.somebookstore.com/findbooks.html  User-Agent  : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) 


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