Packaging a JavaServer Pages[tm] (JSP[tm]) Tag Handler
Class with iPlanet[tm] Application Server, Enterprise Edition 6.0
by Matthew Hosanee
(June 2002)
We'd like to hear from you! Please send us your
FEEDBACK.
The following article may contain actual software programs in source
code form. This source code is made available for developers to use as needed,
pursuant to the terms and conditions of this license.
Overview
The XML document, Tag Library Descriptor (TLD) has an element <tagclass>
(as per the JSP specifications 1.1/1.2 - see the Resources section of this article). This
element is required by the specification and describes the location of the
tag handler class in the form of a fully qualified Java[tm] programming language class name.
When shipping togther in a Web ARchive (WAR) file, the WEB-INF
directory is used as follows:
WEB-INF
Contains the web.xml file
WEB-INF/classes
Contains the tag handler classes
WEB-INF/lib
Contains the JAR files containing additional classes
A TLD file can be stored in the WEB-INF directory but also in a
subdirectory of WEB-INF, and must have the extension .tld.
A simple example TLD file for a tag handler class MyTagTest.class
could look like:
<?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>test</name>
<tagclass>MyTagTest</tagclass>
<info>Outputs a passed string</info>
<bodycontent>EMPTY</bodycontent>
<attribute>
<name>sayThis</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
The TLD file element <tagclass> could suggest that the
class lives in WEB-INF/classes/MyTagTest.class, following the
documentation, guidelines and specification. However, when deploying the WAR,
the JSP does not load and the kjs log reports:
[date time] error: APPLOGIC-caught_exception: Caught Exception:
java.lang.NullPointerException
at com.netscape.server.servlet.platformhttp.PlatformHttpServletResponse.sendError(Unknown
Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.reportError(Unknown
Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unknown
Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown
Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown
Source)
at com.kivasoft.thread.ThreadBasic.run(Native
Method)
at java.lang.Thread.run(Thread.java:484)
[date time] error: Exception: SERVLET-execution_failed: Error in executing
servlet TagLibTest: java.lang.Exception: javac error: /my_install_dir/ias65/
ias/APPS/modules/MyWarName/WEB-INF/compiled_jsp/jsp/APPS/MyWarName/TagLibTest.java:65:
Class jsp.APPS.MyWarName.MyTagTest not found.
MyTagTest _jspx_th_mytablib_test_0 = new MyTagTest();
^
/my_install_dir/ias65/ias/APPS/modules/MyWarName/WEB-INF/compiled_jsp/jsp/APPS/MyWarName/TagLibTest.java:65:
Class jsp.APPS.MyWarName.MyTagTest not found.
MyTagTest _jspx_th_mytablib_test_0 = new MyTagTest();
^
2 errors
Observing the logs you can see that the compiled JSP package is set as
jsp.APPS.MyWarName. The tag library MyTagTest is
not being found in this package.
The solution is to put the tag handler class in a package, as all Java programming language
classes should be. This is done to ensure the uniqueness
of a fully qualified Java programming language class name. The class loader for Web applications
in iPlanet Application Server is shared, so not using a package name could
cause conflicts.
In this way the TLD <tagclass> element could look like:
<tagclass>mypackage.MyTagTest</tagclass>
Resources
The JSP 1.1/1.2 specification can be downloaded from
http://java.sun.com/products/jsp/download.html
The JSP 1.1 DTD can be found from
http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd
The JSP 1.2 DTD can be found at
http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd
|