Learn the Form-related labels provided by Struts.
Continue to learn about the HTML Tag library provided by Struts. By Budi Kurniawan
In the first part of this series, I will show you how to use the HTML Tag library provided by Struts to configure a Struts application. I also introduced a type of tag in the tag Library: Independent tags. In the second part, I will continue to introduce the second type of labels: The labels related to form. 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> label:
<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: