Struts provides a powerful HTML tag library to help you build a web application. BY BUDI Kurniawan For easier, 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; HTML tag libraries are mainly used to display HTML elements, if not this method, you 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 following indicator: <% @ 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 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 a JSP page using the tag: <% @ Taglib URI = / "/ Web-INF / STRUTS-HTML.TLD /" prefix = / "html /"%> "> Welcome title> head> Hello World! body> html: html> Note, we do not use standard elements, It is used tag. 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> html> 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 /"%> < Title> Welcome Title> head> Hello World! body> html: HTML> converted to the following form: < Head> Welcome title> head> Hello World! body> HTML> Tags Tags are used to generate an HTML tab. 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.