Review of JSP Tag Libraries

The Struts tag libraries are nothing more than a specialized set of JSP custom tags. JSP custom tags are a fundamental part of JSP development in general. Some of the advantages of using tag libraries are

  • They enable you to extend and customize JSP functionality

  • They provide a way to avoid using Java scriptlets in your programs by enabling you to embed Java code inside a custom tag

  • They make it easier for non-Java coders to maintain JSP files because understanding how to use a tag is easier than understanding scriptlets

JSP custom tags are created by writing Java code that implements the Tag or BodyTag interface (defined in the package javax.servlet.jsp.tagext).

JSP custom tag development involves three basic steps:

1.
Define the tag syntax— For example, a tag that prints a customer’s name given the customer number might have this syntax: <customer:getName id="idNum" />. This example identifies the tag library prefix (customer), the tag name (getName), and an attribute (id).

2.
Create the tag library descriptor (TLD) file— The TLD file contains information about the overall tag library (the customer tag library, in this case) as well as providing the details for each tag in the library.

3.
Write the actual code that implements the tag— This will be one or more classes that provide handler methods for processing start tags, end tags, tag attributes, and so on.

Note

For a good, basic introduction to JSP custom tag development, you can refer to Sams Publishing’s JavaServer Pages 2.0 Unleashed (ISBN: 0-672-32438-5).

In addition, Sun Microsystems has published a short tutorial at http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset