Improve development speed with label library
Struts provides a powerful HTML tag library to help you build a web application.
BY Budi Kurniawan
In order to make it easier, develop, Struts provides five label libraries similar to other JSP tag libraries, namely: HTML, Bean, Logic, Template and Nested. . The first part tells how to configure a Struts application to use this tag library and introduce the first group of labels; the second part tells the second set of labels;
The HTML tag library is mainly used to display HTML elements. If you don't have this method, you must use the HTML tag to specify them. From the surface, this label library is simple. But through in-depth research, we will find it very powerful. For example, it can place a key content to generate JavaScript in a specific input element of an HTML form, or enter a verification generated script for the client. Moreover, you can use it to handle errors through a line of code. However, before you use this tag library for your Struts application, you need to do some simple preparations.
Configure the application to use the tag library to configure a Struts application through three steps before using the Struts HTML tag library.
1. Register the label library in the deployment descriptor (web.xml file):
taglib>
The above code told the Servlet Container about the situation of the Struts HTML tag library, and where to find the TLD file of the label library.
2. Confirm that the struts-html.tld file is copied to the web-inf directory. You don't have to worry about label library class files because they are already included in the struts.jar file.
3. In each JSP page using the label library, insert the following
<% @ Taglib Uri = "/ Web-INF / STRUTS-HTML.TLD"
Prefix = "html"%>
In addition, you can also use struts-html.tld files to learn what it supports the label and which properties can be taken.
It is usually easy to use a custom label library: as long as you follow the steps described above. However, some tag libraries contain some principles that make us not so easy when using these labels. The Struts HTML tag library is one of them. Some tags are simple, easy to use; however, some labels depend on other tags or other elements in the Struts application.
I am roughly divided into two categories in the HTML tag library: simple, easy to use tags, I call them "independent tags", and the second class is the label that must be used through a FORM label. I simply be simply called the second class of labels related to Form. This article mainly tells the independent label, and I will tell the form-related label in this series of articles.
The HTML tag library contains several easy-to-use independent labels. Here, there are several important labels.
Tags Tag is the easiest label in the HTML tag library. It has two properties: Locale and XHTML, both of which are not required. The following code is selected from a JSP page using the tag:
<% @ Taglib Uri = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
hEAD>
Hello World!
body>
html: html>
Note that we have no standard elements, but use the
hEAD>
Hello World!
body>
html>
Note that
<% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
hEAD>
Hello World!
body>
html: html>
Convert to the following form:
hEAD>
Hello World!
body>
html>
Tags Tags are used to generate an HTML tag. Its most important properties are:
· Page: The image file is relative to the path of the module; there must be a slash.
· Height: The height of the image.
· Width: The width of the image.
· Alt: If the image is not found, the text is displayed.
E.g:
Width = "200" alt = "Company logo" /> Convert to:
Width = "200" alt = "Company logo"> Tags tab generates a hyperlink. For example, tag: Here html: link> Will convert to: Here This tag checks for the property collection of the Request object to find a reserved key. If it finds a reserved key, it assumes that this key is a string, or a string array (which contains Message Keys in the module's MessageResources, or the type ORG.Apache.Struts.Action.ActionerRRRUTS.Action.Actionerror Object. If there is a corresponding information in the application resource, you can use the following optional Message Keys: Errors.Header: The corresponding information is displayed before the individual list of the error message. · Errors.footer: The corresponding information is displayed after the individual list of the error message. · Errors.prefix: The corresponding information is displayed before the individual list of the error message. · ERRORS.SUFFIX: The corresponding information is displayed after the individual list of the error message. The Struts HTML tag library will make development easier and faster. In order to effectively use this tag library, you need to be familiar with the label in the label library. In the first part of this series, you learned how to configure a Struts application to use the label library and have an overall understanding of the independent tag. In the second part, you will learn the labels related to Form;