Develop Faster With Tag Libraries (Continued)
The <img> Tag
The <img> tag is used to generate an HTML <IMG> tag. Its most important attributes include:
-
page: The path to the location of the image file relative to the module; must begin with a slash.
-
height: The height of the image.
-
width: The width of the image.
-
alt: The text displayed if the image cannot be found.
For example, this:
<html:img page="/logo.gif" height="50"
width="200" alt="Company Logo"/>
is translated into:
<img src="/myStrutsApp/logo.gif" height="50"
width="200" alt="Company Logo">
The <link> Tag
The <link> tag generates a hyperlink. For example, this tag:
<html:link page="/index.html">Click
here</html:link>
is translated into this:
<a href="/myStrutsApp6/index.html">Click
here</a>
The <errors> Tag
The <errors> tag's ease of use often belies its real strength. With a tag as simple as <html:errors/>, you can display fully customized error messages that need to appear on a JSP page.
This tag checks the Request object's attributes collection for a reserved key. If the tag finds a reserved key, it assumes that the key is either a String, a String array containing message keys to be looked up in the module's MessageResources, or an object of type org.apache.struts.action.ActionErrors.
These optional message keys will be utilized if corresponding messages exist for them in the application resources:
-
errors.header: If present, the corresponding message will be rendered before the individual list of error messages.
-
errors.footer: If present, the corresponding message will be rendered after the individual list of error messages.
-
errors.prefix: If present, the corresponding message will be rendered before each individual error message.
-
errors.suffix: If present, the corresponding message will be rendered after each individual error message.
I'll discuss the <errors> tag further in Part 3 of this article series.
The Struts HTML tag library makes programming easier and faster. To use it effectively, you need to get yourself familiar with the tags in the library. In this first part of the article series, you learned how to configure a Struts application to use the library and got an overview of the independent tags. Part 2 will discuss the form-related tags, and Part 3 will provide an application that uses the library.
About the Author
Budi Kurniawan is an IT consultant specializing in Internet and object-oriented programming and has taught both Java and Microsoft technologies. He is the author of the best-selling Java for the Web with Servlets, JSP, and EJB: A Developer's Guide to Scalable Solutions (New Riders) and the developer of the most popular Java Upload Bean from BrainySoftware.com, which is licensed and used in projects in major corporations. Contact Budi at .
Back to top
|