Logo         Community
The Company
Your Account
Contact Us
The JSP Files (part 8): Tagged And Bagged
Learn how to speed up JSP code development with custom tag libraries

| Looking Inside |

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.


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

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback