The Tag Handler class
Here is an example of a very simple TagHandler. The doStartTag()
is called after initialization; the tag attributes are used per the JavaBeans[tm]
specification by creating get and set methods.
package mytags;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class MyTagHandler extends TagSupport {
String sayThis;
public int doStartTag()
{
try {
JspWriter out = pageContext.getOut();
out.print("I've been told: " + sayThis);
}
catch(IOException ioe) {
System.err.println("Error with MyTagTest: " + ioe);
}
return (SKIP_BODY);
}
public String getSayThis()
{
return sayThis;
}
public void setSayThis(String
sayThis) {
this.sayThis = sayThis;
}
}
The XML Tag Library Descriptor (TLD) File
The TLD is referenced by the web.xml file, and itself references
the tag handler. The XML specification is described in the JSP specification
and in the URI in the DOCTYPE below.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library
1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tag>
<name>mynewtag</name>
<tagclass>mytags.MyTagHandler</tagclass>
<info>Outputs a passed string</info>
<bodycontent>EMPTY</bodycontent>
<attribute>
<name>sayThis</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
The JSP file
<HTML>
<BODY>
<%@ taglib uri="/myuri" prefix="mytaglib" %>
The output of my custom tag is: <mytaglib:mynewtag sayThis="hello" />
</BODY>
</HTML>
Deployment
This section assumes that the iPlanet Application Server and the Web server
are both installed and configured.
Using the deploytool located in /<install_dir>/ias/bin/,
where <install_dir> is the root of your iPlanet Application
Server install, you will see the following:
Select "Create a new application" and hit "OK". You'll then
be presented with the following:
Select "Web Application(.war)" and enter a filename for the WAR file
(Note: This will be your context in the URL, as you will see later), and the directory
in which you want the WAR to be created. Select "OK".
You will now see the WAR file listed in the Web Applications list,
Select the entry, then select "Edit -> Insert" from the menu (or
right click and select "insert"). From the file selection box select
the JSP, TLD and the "mytags" package containing the tag handler class.
(Note: The "Resolve" button is used to manually select the
paths for JSPs, XML and all static content. Once resolved the file names
should change from red to blue.)
The Web Applications section should now look like this:
To map the new tag lib into the WAR, the web.xml file needs to
be created and updated (the iAS specific XML file will also be created).
Select the WAR file and select "Edit -> Edit Descriptor" from
the menu. You should be presented with the following window; select
the "Servlet" tab.
Click "Add" to add the tag library. The URI is the URI as
specified in the JSP file. For example, "/myuri". The
TLD location is the location in the WAR file for example "/WEB-INF/tlds/mytaglib.tld".
Select "File -> Save from the menu" to save the WAR.
You can now deploy from "File -> Deploy".
Resources
The iPlanet Application Server, Enterprise Edition 6.5 Developer Documentation
http://docs.iplanet.com/docs/manuals/ias/65/devguide/contents.htm
The Java[tm] Web Services Tutorial, at
http://java.sun.com/webservices/tutorial.html
The JSP 1.1 specification, which can be downloaded from
http://java.sun.com/products/jsp/download.html
The JSP 1.1 DTD, which can be found at
http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd
The main JSP tag libraries page, which can be found at
http://java.sun.com/products/jsp/taglibraries.html
DOC ID #1190