Class 2 |
Intermediate Java 30-IT-397 |
|
The JSP File
-
First, write the tag handler class and the .tld file. Then, you can
hack away at the jsp.
-
Before you use the tag, you must use the taglib directive. There
are two acceptable forms.
-
<%@ taglib uri="mytaglib.tld" prefix="mytags" %>
-
This points directly to the .tld file. It is the quickest, but least
flexible.
-
<%@ taglib uri="/mytags" prefix="mytags" %>
-
This will look in the web.xml deployment file first. This XML file
has a <taglib> tag with two subtags, <taglib-uri>
and <taglib-location> that define where the .tld file is located.
That makes it easy to change locations without changing the source code
if you need to.
-
You use the prefix, followed by a colon and the tag name, to access the
tag throughout your jsp. Just make sure to put the taglib directive
first!
-
For example, if the previous tld were saved in the root directory and named
named mytaglib.tld, and we wanted to access the foo tag, we would use this
syntax:
<%@ taglib uri="mytaglib.tld" prefix="mytags" %>
<mytags:foo att1="98.5" att2="92.3" att3="107.7">
Detour: Deploying Tags in Tomcat
More About Tags

Created by: Brandan Jones
December 20, 2001