Detailed explanation of JSP Struts HTML Tag Library

Source: Internet
Author: User

Jsp (preferred for SUN Enterprise Applications) detailed explanation of Struts-based HTML Tag Library
Struts provides five tag libraries: HTML, Bean, Logic, Template, and Nested.
Tag library description
HTML tags are used to create HTML input forms that can interact with the Struts Framework and other corresponding HTML tags.
Bean labels are used to access JavaBeans and their attributes and define a new bean.
Output Produced by Logic tag management conditions and cycle generated by object sets
Template label with the appearance of the Tiles framework package, this label has been reduced
Nested labels enhance the Nested use of other Struts labels

 
Common Features of tags
 
Use the Struts tag with a fixed attribute name:
Attribute description
Id: name of the script variable when the custom tag is created.
Name indicates the keyword value. An existing bean can be found under this keyword. If the scope attribute is provided, you can only search for it in the scope. Otherwise, search for (page, request, session, or application) in various scopes in the standard order ).
Property indicates an attribute in the bean, where values can be retrieved. If not specified, the object value is used.
Scope defines the scope in which the Bean is located (page, request, session, or application. If not, search in order. The script variable (see id) will be created in the same range.

 
Struts labels also support nested references, such:
Property = "foo. bar. baz"

This is equivalent to the following call:
GetFoo (). getBar (). getBaz ();

Or as setter:
GetFoo (). getBar (). setBaz (value );

 
Although Struts labels are designed to avoid using scriptlet, The scriptlet expressions can also be provided to all Struts labels. Make sure that the complete expression is used:
Error:
<Html: link href = "<% ="/"+ name %>/index. jsp (preferred for SUN Enterprise Applications)>
 
Correct:
<Html: link href = "<% ="/"+ name +"/index. jsp (preferred for SUN Enterprise Applications) "%> // The expression must provide the entire Attribute Value

 
 
Html Tag Library
1. It has two attributes: locale and xhtml, both of which are not required.
<Html: html locale = "true">

After this line of code is parsed:
<Html lang = "en">

2. Note: The generated result depends on the locale of the server on which the Struts application is located. If you deploy the application to a server with different locale, you do not need to change the code, Locale will automatically adjust.
3. <base> label: indicates the absolute position of the page contained. This label is valid only when embedded in the head label.
<Html: base/>

After this line of code is parsed:
<Base href = "http://www.mymain.com/myStrutsApp/testing.jsp (preferred for SUN Enterprise Applications)">

4. label
The most important attribute page: the path of the image file, which must be preceded by a diagonal line.
Other attributes: heignt, width, and alt.
<Html: img page = "/logo.gif" height = "50" width = "200" alt = "Web Logo"/>

5. <link> label
<Html: link page = "/index.html"> Click demo

After this line of code is parsed:
<A href = "/index.html"> Click demo </a>

6. <errors> label: A simple Note: This tag searches for the reserved key in the property set of the Request object. If it finds a reserved key, it assumes that the key is a String or a String array.
(It contains the message keys found in MessageResources of the module), or an object of the type org. apache (the most popular WEB server platform on the Unix platform). struts. action. ActionErrors.
If the corresponding information exists in the Application resource, you can use the following optional message keys:
· Errors. header or errors. prefix: the corresponding information is displayed before the separate list of error messages.
· Errors. footer or errors. suffix: the corresponding information is displayed after the separate list of error messages.
7. <form> tag Series
When using the <form> label, you must follow the following rules:
1. A tag must contain an action attribute, which is the only required attribute in the tag. If this attribute is not available, the jsp (preferred for SUN Enterprise Applications) page throws an exception. You must specify a valid value for this action attribute. A valid value is the access path of any child element in the Struts configuration file of the application. The corresponding element must have a name attribute. Its value is the name of form bean.
<Html: form action = "/login">

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.