Java Reference
In-Depth Information
FIGURE 21.1
Collecting informa-
tion with a web
form.
The form is contained within the
<form>
and
</form>
HTML tags. Each field on the
form is represented by its own tags:
textarea
for the text area and
input
for the
Translate button. The text area is given a name, “text”.
Servlets require you to have a basic familiarity with HTML because
the only user interface for a servlet is a web page running in a
browser. Two topics that are good for learning HTML are
Sams
Teach Yourself HTML and CSS in 24 Hours, Seventh Edition
, by Dick
Oliver and Michael Morrison (ISBN 0-67232-841-0) and
Sams
Teach Yourself Web Publishing with HTML and CSS in One Hour a
Day, Fifth Edition
, by Laura Lemay and Rafe Colburn (ISBN 0-
67232-886-0).
TIP
Each field on a form stores information that can be transmitted to a web server and then
sent to a Java servlet. Web browsers communicate with servers by using Hypertext
Transfer Protocol (HTTP). Form data can be sent to a server using two kinds of HTTP
requests:
get
and
post
.
When a web page calls a server using
get
or
post
, the name of the program that handles
the request must be specified as a web address, also called a
uniform resource locator
(URL)
.
A
get
request affixes all data on a form to the end of a URL, as in this example: