|
Develop Faster With Tag Libraries
Struts provides a powerful HTML tag library to help you build your Web apps.
by Budi Kurniawan
Posted January 9, 2003
For easier and faster development, Struts provides five tag libraries that act and function just like other JSP tag libraries: HTML, Bean, Logic, Template, and Nested. This three-part article series covers the HTML tag library. Part 1 discusses how to configure a Struts application to use this library and its first group of tags, Part 2 explains the second group of tags, and Part 3 demonstrates an application that uses this library. This article assumes you have a basic knowledge of Struts. If you don't, please read my six-part Struts tutorial.
The HTML tag library is mainly used to render HTML elements that otherwise must be specified using HTML tags. On the surface, this tag library looks simple. But deep down inside, it's powerful. For example, it can generate JavaScript for placing focus in a specific input element in an HTML form or scripts for client-side input validation. Also, you can use it to handle errors with a single line of code. Before you can use this library in your Struts application, however, you need to do some simple preparation.
Configuring Applications to Use the Library
You need to take three steps to configure a Struts application before you can use the Struts HTML tag library.
1. Register the library in the deployment descriptor (web.xml file):
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
This tells the servlet container about the Struts HTML tag library and where to find the tag library's TLD file.
2. Make sure the struts-html.tld file is copied to the WEB-INF directory. You don't have to worry about the library class files because they are already included in the struts.jar file.
3. In every JSP page that uses the tag library, insert this <taglib> directive:
<%@ taglib uri="/WEB-INF/struts-html.tld"
prefix="html" %>
Also, the struts-html.tld file is the reference you should use to learn the supported tags and what attributes each tag can take.
Back to top
|