Java Reference
In-Depth Information
Figure 7.1: A HTML form
To write a Java program that can respond to a form, you must learn to examine forms in
HTML. In this section, we will examine each of the HTML tags that make up a form. If you
are already familiar with form HTML code, you can safely skip to the next section.
Form Tag
The actual
<form>
tag contains two very useful pieces of information. First, the
<form>
tag tells you if the form request should be an HTTP
GET
or an HTTP
POST
request. Each of these two request types are handled differently. Second, the
<form>
tag
tells you which URL the HTTP request should be sent to. Consider the following
<form>
tag:
<form method="get" action=”/process.php”>
The
method
attribute of this tag tells us that this will be an HTTP
GET
request. The
action
attribute of this tag tells us that the request will go to
/process.php
. A
POST
<form>
element looks very similar:
<form method="post" action=”/process.php”>
The main difference between the two, is that the second tag specifies that this request
uses the HTTP
POST
, and not the HTTP
GET
.