Java Reference
In-Depth Information
to define the number of columns. As indicated in lines 35 and 36 of Figure 12-7
on page 787, within the first row, the first column has a width that is one-third
(33%) of the entire table width. Within the table cell, the image tickerScrn.wmf
is center-aligned and scaled to a height and width given in screen pixels.
Creating a Form in an HTML Document
The form begins in the next column, with a table nested within the form. In
line 39, the <form> tag introduces a form with a name attribute of logonScreen.
This is the same form referenced earlier in the onLoad() event handler of the
<body> tag. Two other attributes, method and action, are assigned values.
HTTP GET AND POST METHOD ATTRIBUTES The method attribute of
a form specifies which HTTP method, either Get or Post (case-insensitive), is
used to send a request for service to the server. Requests usually are accompanied
by form data, sent as a series of name=value parameters. The Get method is the
default HTTP method for sending data. It transfers parameters by appending
them to the URL, making them visible to the user. The Get method executes
slightly faster than Post and allows the user to bookmark parameters along with
the Web page; however, the amount of data that can be sent via the Get method
is restricted to 4 KB of data or less. Additionally, the Get method restricts form
data to ASCII characters only. The Post method sends parameter data without
appending to the URL, so the data are not directly visible to the user, although
they are not necessarily secure, either. If the parameters should not be visible, or
more than 4 KB of data must be transferred, then the Post method must be used.
ACTION ATTRIBUTES The action attribute of a form specifies the address
of a program which will process the form data when the form is submitted,
either by the Get or Post method. Typically, this specifies a program on the Web
server, such as a CGI program or, as shown in line 39, a servlet. Unless a com-
plete URL is listed in the action attribute, it defaults to a location relative to the
document. The address for a servlet is specified with servlet/ before the servlet
name, indicating that a servlet is requested. What appears as a servlet folder is
translated on the server to the actual folder for the servlet, as discussed later.
OBTAINING FORM DATA WITH INPUT TAGS Within a form, input tags
are used to collect data from the user. An input tag can have several attributes,
depending on the type of the input element. Input tags of the type, text, as
shown in line 57, display a text box in a form. Input tags of the type, password,
as shown in line 65, display a text box normally used to enter a password. A text
box with a password type automatically displays asterisks rather than the data
entered by the user, although the entered data is sent to the server as plain text.
For both text and password input elements, the size attribute controls the
displayed width of the text box in characters; the name attribute assigns the
element a name, such as UserID or password.
An input tag with the type attribute of button displays a button that the user
can click. Typically, a form includes a button when some action other than an
immediate submission of the data is needed. Line 70 defines a button which,
when clicked, calls the JavaScript validate() function and passes a reference to the
form, logonScreen. Line 76 defines a button of type reset, which causes all input
Search WWH ::




Custom Search