Professional Java Server Programming J2EE Edition
Chapter 12
hello.jsp
META-INF/
MANIFEST.MF
WEB-INF/
web.xml
classes/
tagext/
HelloTag.class
tlds/
hello.tld
There are a few WAR conventions specific to using tag libraries. We should place our tag library descriptor
files in the WEB-INF/tlds directory. We need to use a special element in the web.xml file, <taglib>, to
let the server know where to find the tag library's TLD within the WAR when JSPs in the WAR attempt to
import it. The following is the web.xml file for the simple example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
'-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN'
'http://java.sun.com/j2ee/dtds/web-app_2.2.dtd'>
<web-app>
<display-name>tagext</display-name>
<description>Tag extensions examples</description>
<session-config>
<session-timeout>0</session-timeout>
</session-config>
<!-- Tag Library Descriptor -->
<taglib>
<taglib-uri>/hello</taglib-uri>
<taglib-location>/WEB-INF/tlds/hello.tld</taglib-location>
</taglib>
</web-app>
The easiest way to create the WAR is first to create the directory structure corresponding to the WAR's
structure in your development environment. All we then need to do to build the WAR is to then issue the
following command in the WAR's root directory. Note that we exclude the .java source files, which would
unnecessarily inflate our WAR and may cause problems when we attempt to deploy it:
jar -cvf hello.war META-INF/MANIFEST.MF WEB-INF/classes/tagext/*.class WEB-
INF/tlds/hello.tld WEB-INF/web.xml *.jsp
As mentioned above, deploying this WAR on Tomcat 3.1 simply requires copying the WAR into the
$TOMCAT_HOME/webapps directory. When Tomcat is started, it automatically unpacks the WAR and
creates the application, with the application's name (and context path) being the name of the WAR. There is
no need to make any changes to the system or server classpath. Each web application will be given its own
classloader at runtime.
There is another way of deploying WARs in Tomcat, which is much more convenient during
development. Tomcat lets us work on a WAR that exists not as a single file, but as an expanded
directory structure. This makes development a lot easier. It's not necessary to restart Tomcat when
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.