Java
  Home arrow Java arrow Page 3 - The JSP Files (part 8): Tagged And Bag...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

The JSP Files (part 8): Tagged And Bagged
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2001-06-11

    Table of Contents:
  • The JSP Files (part 8): Tagged And Bagged
  • Playing Tag
  • Looking Inside
  • Meeting Popeye
  • You've Got Mail!
  • Applet Antics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    The JSP Files (part 8): Tagged And Bagged - Looking Inside


    (Page 3 of 6 )

    A tag library is made up of several components. First comes the tag class itself, written in Java - this contains all the behind-the-scenes code which makes the tag function. This class will be referenced in the tag library descriptor, and constitutes the meat of the sandwich we're building.

    Next, you need a "tag library descriptor", an XML file usually identified with the .TLD file extension. This TLD contains information on different aspects of the tag library: the name of the tag, and of the Java class associated with it, a short description of functionality, and optional attributes and body content.

    Both these components are usually packaged into a JAR file for easy distribution.

    Now, we're not going to get into the nitty-gritty of writing a tag library here - there are already a whole bunch of tutorials which discuss this in detail, and links to some are included at the end of this article. What we will do, however, is illustrate how a tag library can be incorporated into your JSP document, and how it interacts with the rest of your script.

    In order to illustrate this, we'll be using the Jakarta Project's DATETIME tag library, designed to manipulate date- and time-stamps. You can download a copy of this library from http://jakarta.apache.org/taglibs/doc/datetime-doc/intro.html, and you can find a number of other freeware tag libraries at http://www.jsptags.com/, one of the larger repositories on the Web.

    Once you've downloaded a copy of the library, you need to tell Tomcat about it before you can begin using it. The first step here is to decide the context within which you plan to use the library - for purposes of this example, we will assume the context is "/test/". Next, copy the TLD file from the distribution into the context's "web-inf/" directory, and the main JAR file into the context's "web-inf/lib/" directory.

    The last step here is to open up the "web.xml" file which resides in the "web-inf/" directory, and alter it to reflect the new tag library - this is accomplished via the <taglib> directive.


    <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/datetime-1.0</taglib-uri> <taglib-location>/WEB-INF/datetime.tld</taglib-location> </taglib>

    This element specifies the location of the tag library, as well as a unique URI used to reference it.

    More Java Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    JAVA ARTICLES

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway