10.7. ServletRequest and HttpServletRequest

The ServletRequest and HttpServletRequest classes hold all of the accessible information about the client and the server. HttpServletRequest is a subclass of ServletRequest, and is passed to each servlet handler method (such as doGet(..), doPut(..), etc.) This request may be in the form of parameters, a text or binary body, or a combination of both.

In addition, most of the standard CGI environment variables have corresponding methods that allow easy access, such as CONTENT_LENGTH and the getContentLength(). Others require an explicit request via the getHeader() method, such as HTTP_USER_AGENT and REMOTE_ADDR. Commonly used variables are shown in Table 10-2.

Table 10-2. CGI Variables that a Servlet ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.