In order to make the development speed for easier and rapid development, Struts provides five label libraries similar to other JSP tag libraries, namely: HTML, Bean, Logic, Template and Nested. This series of articles describe the HTML tag library by three parts. 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; Part III takes an example to tell how to use this tag library. The premise of learning this series is that you have already had a basic understanding of Struts. If you don't know much, please read the series of articles I wrote about Struts (six parts). 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 label in deployment descriptor (web.xml file): /web-inf/struts-html.tld taglib-uri> / web-inf /struts-html.tld taglib-location> taglib> The code above told the Servlet Container about the situation of the Struts HTML tag library, and where to find the tag library TLD file. 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 indicator: <% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%> In addition, you You can also use struts-html.tld files to learn what it supports the label and which properties can be brought by each tag. 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 the JSP page using the tag: <% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%> Welcome title> head> Hello World! body> html: html> Note that we have no standard elements, but use label. The first HTML refers to the prefix, the second is the tag itself. And we also used the local property. The JSP page will be displayed: Welcome title> head> hello world! Body> Note, The local property in the generated HTML page is converted into lang = "en". The resulting result depends on the locale of the server located at the Struts application. If you deploy an application to a different locale server, you don't need to change the code. Locale will automatically adjust. Tags Tag Displays an HTML element that represents the absolute position of the included JSP page with an HREF property. It is only valid when this tag is embedded in a Head tag portion. For example, this JSP page: <% @ taglib URI = "/ Web-inf / struts-html.tld" prefix = "html"%> Welcome title > head> Hello World! body> html: html> Convert to the following form: Welcome Title> head> Hello World! body> html> tab tab Used to generate an HTML tag. Its most important attributes are: • Page: Image file relative to the path of the module; you must have 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.