Java Reference
In-Depth Information
the type of data the browser can expect. In this case, the data type is text/html. This
information is included in the header portion of the response. Web servers map file
extensions to MIME types. An image file might have the MIME type image/gif.
How the file is rendered by the browser depends on the browser, but only cer-
tain types are interpreted directly by most browsers. These include HTML and im-
ages in GIF or JPEG format. A file whose type is not recognized directly by the
browser may be passed to an external “viewer” application, such as a sound player.
The browser receives the response, reads the HTML, and formats the display.
The transaction is complete and the connection between the browser and the
server is closed.
As mentioned earlier, the URL after the pathname may have a query string. The
query string consists of one or more parameters followed by their values. Each pa-
rameter consists of a parameter name followed by an equals sign and the parame-
ter value. Parameters are distinguished from each other by an ampersand (&).
For example, the query string ?x=5&y=7&z=1+2+3 has three parameters: x, y,
and z. The parameter x has the value of 5; y has the value of 7. The parameter z is
an array with values 1, 2, and 3.
The types of characters that can be passed in a query string are restricted to al-
phanumeric characters, certain reserved characters (:/?#”<>%+), and a few other
characters ($-_.&+). If you need to pass anything else, it must be encoded. Charac-
ters are encoded as a “%” followed by two hexadecimal digits that represent the
value of the character.
The browser request can be in one of two forms, GET and POST. A GET re-
quest is simply a request for data as identified in the URL. A POST request includes
additional information in the request, in the message body. For example, if you
enter information in a Web search portal and click the Search button, your search
terms are sent in the message body that is included in the POST request to the
search Web site.
T HE S ERVLET AS T RANSACTION P ROCESSOR
To oversimplify things a little, a servlet is a Java program invoked by a Web server
to respond to a request from a browser. A servlet responds to requests from the
browser and builds HTML output. It is transaction-based. The request arrives; the
servlet processes it and builds the response. The Web server routes the response
Search WWH ::




Custom Search