The form-related labels include the <form> label and all the labels that must be included in the label. For example, the <text> and <password> labels are form-related labels, because they are meaningless if they are not put in a form.
<Form> label
<Form> A tag is used to generate an HTML form. Many rules must be followed when using this label.
First, the <form> tag must contain an action attribute, which is the only required attribute in the tag. If this attribute is not available, the JSP page throws an exception. You must specify a valid value for this action attribute. A valid value is the access path of any <action> sub-element in the <action-mappings> element in the struts configuration file of the application. The corresponding <action> element must have a name attribute. Its value is the name of form bean.
For example, if you have a <form> tag: <HTML: Form Action = "/login">
The <action-mappings> element in your struts configuration file must contain the following <action> element in bold:
<Action-mappings>
<Action Path = "/login"
Type = "com. javapro. Struts. loginaction"
Name = "loginform"
Scope = "request"
Input = "/login. jsp">
<Forward name = "success" Path = "/mainmenu. jsp"/>
</Action>
.
.
.
</Action-mappings>
This means that a form tag is associated with form bean.
Another rule to be followed is: any labels (<text>, <password>,
In addition to the attributes mentioned above, the <form> tag has some attributes that are not mandatory but are better "secondary. For example, you can use the focus attribute to generate JavaScript, which will "Focus" on an element contained in the form. You need to specify the element name for the focus attribute. For example, the following code is fixed on the second text element: <body>
<HTML: Form Action = "/login" Focus = "password">
User name: <HTML: Text property = "username"/>
<Br> password: <HTML: Text property = "password"/>
<Br> <HTML: Submit/>
</Html: Form>
</Body>
This section of code will be converted:
<Body>
<Form name = "loginform" method = "Post"
Action = "/mystrutsapp6/login. Do">
User name: <input type = "text" name = "username"
Value = "">
<Br> password: <input type = "text"
Name = "password" value = "">
<Br> <input type = "Submit"
Value = "Submit">
</Form>
<Script language = "JavaScript"
Type = "text/JavaScript">
<! --
If (document. Forms ["loginform"]. elements [
"Password"]. type! = "Hidden ")
Document. Forms ["loginform"]. elements [
"Password"]. Focus ()
// -->
</SCRIPT>
</Body>
Note: The default value of the method attribute in the <form> label is post. In addition, have you seen how this tag Library builds JavaScript to focus on the password element? This is also a fascinating part of the library. You don't have to worry about how to program on the client, it will automatically generate for you.
When running the preceding example, note that you must have a form that contains the username and password attributes. You can refer to the login program in the third part of this article.
<Text> label
<Text> label is used to generate an input area of text. It must contain the "property" attribute corresponding to the same attribute in the related form bean. This label is valid only when it is embedded into a <form> label.
Example: <HTML: Text property = "username"/>
Will be converted to: <input type = "text" name = "username" value = "">
<Password> tag
<Password> the tag is used to generate a type password input area. It must contain the "property" attribute corresponding to the same attribute in the related form bean. This label is valid only when it is embedded into a <form> label. A very important attribute in this label is "redisplay", which is used to re-display the value previously entered in this area. The default value of this attribute is true. However, to prevent the password from being re-displayed, you may want to set the value of this attribute to false.
Example: <HTML: Password property = "password" redisplay = "false"/>
Is converted to: <input type = "password" name = "password" value = ">
<Hidden> tag
<Hidden> the tag is used to generate an input area for hidden text. It must contain the "property" attribute corresponding to the same attribute in the related form bean. This label is valid only when it is embedded into a <form> label:
Example: <HTML: hidden property = "username"/>
Will be converted to: <input type = "hidden" name = "username" value = "">
<Textarea> label
<Textarea> A tag is used to generate a text area element ). It must contain the "property" attribute corresponding to the same attribute in the related form bean.
For example:
<HTML: textarea property = "details" Cols = "80" rows = "20" value = "enter details here"/>
Will be converted:
<Textarea name = "details" Cols = "80" rows = "20"> enter details here </textarea>
<Radio> label
<Radio> the tag is used to display a single-choice button ). It must contain the "value" attribute. For example: <HTML: Radio property = "title" value = "1"/> mr.
<HTML: Radio property = "title" value = "2"/> MS.
<HTML: Radio property = "title" value = "3"/> dr.
Will be converted to such HTML:
<Input type = "radio" name = "title" value = "1"> mr.
<Input type = "radio" name = "title" value = "2"> MS.
<Input type = "radio" name = "title" value = "3"> dr.
<Checkbox> label
<Checkbox> the label is used to display the checkbox type input area. For example:
<HTML: checkbox property = "Y"/> Please send me notification
Will be converted:
<Input type = "checkbox" name = "Y" value = "on"> Please send me notification
<Submit> label
<Submit> the label is used to generate the input area of the type submit.
For example: <HTML: Submit value = "login"/>
Will be converted to: <input type = "Submit" value = "login">
<Reset> tag
<Reset> A tag is used to generate an input area of the reset type (Type reset. For example:
<HTML: reset/>
Will be converted to: <input type = "reset" value = "reset">
<Option> label
<Option> A label is used to display an option in select box. Refer to the <SELECT> label below.
<SELECT> label
<SELECT> A tag is used to display an HTML selection element that contains zero or more options. It is valid only when it is embedded with a <form> label. The following example shows how to use the tag: <HTML: Select Property = "color" size = "3">
<HTML: option value =
"R"> Red <HTML: option value =
"G"> green <HTML: option value =
"B"> blue </Html: Select>
Will be converted:
<Select name = "color" size = "3"> <Option
Value = "R"> Red </option>
<Option value = "G"> green </option>
<Option value = "B"> blue </option>
</SELECT>