Java
  Home arrow Java arrow Page 9 - Overview of Java Web Technologies, Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Overview of Java Web Technologies, Part 2
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2004-03-03


    Table of Contents:
  • Overview of Java Web Technologies, Part 2
  • Sun's Solution
  • JSP and JavaBeans
  • Calling a Bean from a JSP Page
  • Accessing Bean Properties
  • Custom Tags
  • Developing and Using Custom Tag Libraries
  • Writing a Tag Handler
  • Writing and Using Tags
  • Model 2 Architecture

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Overview of Java Web Technologies, Part 2 - Writing and Using Tags
    ( Page 9 of 10 )

    Writing a Tag Library Descriptor (TLD)

    A TLD is an XML document that describes a tag library. A TLD is validated against a DTD file. Currently, the latest version of the DTD is 1.2. A TLD must begin with the following header:

     
    <?xml version="1.0" encoding="ISO-8859-1" ? > 
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag 
    Library 1.2//EN" 

    "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"

    The root element of a TLD file is <taglib>. The subelements for the taglib element are as follows:

     
    <!ELEMENT taglib (tlib-versionjsp-versionshort-nameuri?, 
    display
    -name?, small-icon?, large-icon?, description?, validator?, 
    listener
    *, tag+) > 

    A taglib element must have the following elements:

    • The tlib-version element specifies the version of the tag library implementation.
    • The jsp-version element defines the JSP version that the tag library can work with.
    • The short-name element encloses a unique name for the tag library.
    • The tag element specifies a custom tag in the library. Its subelements are as follows:

     
    <!ELEMENT tag (nametag-class, tei-class?, body-content?, 
    display
    -name?, small-icon?, large-icon?, description?, variable*, 
    attribute
    *, example?) > 

    The other subelements are optional. You can read the description of each element in the DTD file downloadable from http://java.sun.com/dtd/web-jsptaglibarary_1_2.dtd.

    Using a Custom Tag in a JSP Page

    To use a custom tag in a JSP page, you need to be familiar with the taglib directive in JSP. A taglib directive has the following syntax:

     
    <%@ taglib uri="tagLibraryURI" prefix="tagPrefix" %> 

    The uri attribute specifies an absolute or relative URI that uniquely identifies the TLD associated with this prefix. The prefix attribute defines a string that will become the prefix to distinguish a custom action.

    With a taglib directive, you can use a custom tag of the following format for a custom tag that does not have a content body:

     
    <prefix:tagName/> 

    Or, you can use the following format for a custom tag that has a content body:


    <prefix:tagName>body</prefix:tagName

    You can pass attributes to the tag handler by specifying the attributes in the custom tag, each with the following format:

     
    attributeName="attributeValue" 

    The following example is a custom tag whose prefix is m and whose name is myTag. The tag has two attributes: number, with a value of 12, and power, with a value of 13.

     
    <m:myTag number="12" power="13"/> 

    Note that an attribute value must be enclosed in quotation marks.



     
     
    >>> More Java Articles          >>> More By McGraw-Hill/Osborne
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT