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.




Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net