44° Chapter 3: Javabeans and Forms =
3.1.1 An Overview of HTML Forms
‘An HTML, or XHTML, form is created using the forn element.! This element wraps the
desired form controls into a single construct, which is encapsulated between the form's
start and end tags. The form element takes several arguments, which control the overall
behavior of the form. Of these attributes, the three most commonly used are nane, action,
‘and nethod. Other attributes can be used for controlling the presentation of the form,
specifying what happens when certain events occur (for example, when the “submit” button
1s clicked), and defining the actual processing behavior of the server,
‘The name attribute provides a unique name for the form. This can be used at the Web
server to access the data submitted by the form. The action attribute, which is required,
specifies what should be done when the form is submitted. Typically this attribute spec
ifies @ Universal Resource Indicator (URI) that will process the form data (for example,
account. jsp). The method attribute specifies what Hypertext Transport Protocol (HTTP)
transport method—GET or POST—should be used to submit the form data.
‘The GET method, which is the default value, will append the data to the URI specified
by the action attribute. Because Web browsers and servers can support different Universal
Resource Locator (URL) maximum lengths, the GET method should not be used for large
quantities of data; a good rule is to stay below 100 characters. The POST method, on the
other hand, includes the form data as part of the body of the HTTP request. However, the
POST method does not work with bookmarks.
‘The actual work in an HTML form is accomplished by controls. A control is a spe.
cific mechanism for obtaining input from the user. The different controls can be globally
categorized as follows
"= Button: A button control comes in three flavors: submit, reset, and push. A button
‘control can be created using the input or button elements.
= Checkbox: A checkbox control can take two values: on or off. Checkbox controls are
created using the input element and can be grouped together by having multiple
controls share the same name, This enables a single control name to have multiple
values,
= Radio Button: A radio button control can take two values: on oF off. Radio button
controls are created using the input element and can be grouped together by having
multiple controls share the same name. In the case of grouped radio button controls,
however, only one radio button in the group can selected, or on,
= Menu: A menu control, or a drop-down list, allows multiple options to be presented in
‘minimal space. The menu control is created using the select, option, and optgroup
elements.
1 Text Input: A text input control allows a user to enter arbitrary text. The input element
‘can be used to create a single-line text input control, which Is useful for entering a
"The full specification for HTML forms is available at http: //www.w3.org/TR/html4/interact/forms.
.