PreviousNext
JavaScript must be enabled to correctly display this content
5 Administration and Configuration
The following topics provide an overview of administration and configuration tasks for using JSP tag extensions.
Configuring JSP Tag Libraries
You can configure a JSP tag library as well as package a tag library as a JAR file.
To deploy the example tag library as files in a web application:
Create the Jakarta Pages 4.0 TLD shown in Chapter 3. Save it as /WEB-INF/library.tld in the web application. Its <uri> element is <uri>myTLD</uri>.
Compile examples.webapp.jsp.tags.ext.quote.CodeTag and place its class file at /WEB-INF/classes/examples/webapp/jsp/tags/ext/quote/CodeTag.class. Put any additional handler classes required by the TLD under /WEB-INF/classes using their Java package paths.
In the JSP page that uses the library, add <%@ taglib uri="myTLD" prefix="mytaglib" %>.
Invoke the tag declared by that TLD, for example <mytaglib:code>text to format</mytaglib:code>.
Deploy the web application to WebLogic Server. The container discovers /WEB-INF/library.tld and maps its declared URI, myTLD, without a web.xml taglib entry.
If this application uses an explicit mapping for the same library, put the “Explicit web.xml mapping” fragment below inside the existing <web-app> element of /WEB-INF/web.xml. Do not add a second <web-app> root.
Explicit web.xml mapping: The mapping is optional for this example because library.tld already declares myTLD. If the application includes an explicit mapping, use exactly this fragment:
You can also package a JSP tag library as a JAR file.
To package the Chapter 3 code-tag library as a JAR file:
Save the Chapter 3 Jakarta Pages 4.0 TLD as taglib-staging/META-INF/taglib.tld. It contains <uri>myTLD</uri> and names examples.webapp.jsp.tags.ext.quote.CodeTag as the handler.
Compile CodeTag and place CodeTag.class at taglib-staging/examples/webapp/jsp/tags/ext/quote/CodeTag.class. Place any other classes named by this TLD under taglib-staging in their matching Java package directories.
Before creating the JAR, the staging layout must look like this:
From the directory that contains taglib-staging, run these two commands. The first archives the contents of taglib-staging at JAR root; the second lists the resulting entries:
jar --create --file myTagLibrary.jar -C taglib-staging .
jar --list --file myTagLibrary.jar
Confirm that the listing contains META-INF/taglib.tld and examples/webapp/jsp/tags/ext/quote/CodeTag.class. It must not prefix either path with taglib-staging/.
Copy myTagLibrary.jar to /WEB-INF/lib/myTagLibrary.jar in the web application.
In the JSP page, use <%@ taglib uri="myTLD" prefix="wl" %> and then invoke the declared tag, for example <wl:code>text to format</wl:code>. No web.xml taglib mapping is needed because META-INF/taglib.tld declares the URI myTLD.
<%@ taglib uri="myTLD" prefix="wl" %>
The container discovers META-INF/taglib.tld inside the JAR in /WEB-INF/lib and maps the TLD's myTLD URI to that library. No explicit web.xml taglib mapping is required for this example.