Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
A.4 Handling the Client Request: HTTP Request Headers
525
public int getIntHeader(String headerName)
Reads header that represents an integer and converts it to an
int
.
Returns 1 if header not in request. Throws
NumberFormatException
for non ints.
public Cookie[] getCookies()
Returns array of
Cookie
objects. Array is zero length if no cookies. See
Chapter 8.
public int getContentLength()
Returns value of
Content Length
header as
int
. Returns 1 if
unknown.
public String getContentType()
Returns value of
Content Type
header if it exists in request (i.e., for
attached files) or
null
if not.
public String getAuthType()
Returns
"BASIC"
,
"DIGEST"
,
"SSL"
, or
null
.
public String getRemoteUser()
Returns username if authentication used;
null
otherwise.
Other Request Information
public String getMethod()
Returns HTTP request method (
"GET"
,
"POST"
,
"HEAD"
, etc.)
public String getRequestURI()
Returns part of the URL that came after host and port.
public String getProtocol()
Returns HTTP version (
"HTTP/1.0"
or
"HTTP/1.1"
, usually).
Common HTTP 1.1 Request Headers
See RFC 2616. Get RFCs on line starting at http://www.rfc editor.org/.
Accept: MIME types browser can handle.
Accept Encoding: encodings (e.g., gzip or compress) browser can
handle. See compression example in Section 4.4.
Authorization: user identification for password protected pages. See
example in Section 4.5. Normal approach is to not use HTTP
authorization but instead use HTML forms to send username/password
and then for servlet to store info in session object.
Connection: In HTTP 1.0,
keep alive
means browser can handle
persistent connection. In HTTP 1.1, persistent connection is default.
Servlets should set
Content Length
with
setContentLength
(using
ByteArrayOutputStream
to determine length of output) to support
persistent connections. See example in Section 7.4.
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