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:

  1. 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>.
  2. 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.
  3. In the JSP page that uses the library, add <%@ taglib uri="myTLD" prefix="mytaglib" %>.
  4. Invoke the tag declared by that TLD, for example <mytaglib:code>text to format</mytaglib:code>.
  5. 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.
  6. 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:

    <jsp-config>
      <taglib>
        <taglib-uri>myTLD</taglib-uri>
        <taglib-location>/WEB-INF/library.tld</taglib-location>
      </taglib>
    </jsp-config>

Packaging a JSP Tag Library as JAR File

You can also package a JSP tag library as a JAR file.

To package the Chapter 3 code-tag library as a JAR file:

  1. 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.
  2. 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.
  3. Before creating the JAR, the staging layout must look like this:
    taglib-staging/
    ├── META-INF/
    │   └── taglib.tld
    └── examples/
        └── webapp/jsp/tags/ext/quote/CodeTag.class
  4. 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
  5. 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/.
  6. Copy myTagLibrary.jar to /WEB-INF/lib/myTagLibrary.jar in the web application.
  7. 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.