Skip navigation.

Programming WebLogic JSP Tag Extensions

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents Index View as PDF   Get Adobe Reader

Overview of Programming JSP Tag Extensions

The JSP 1.1 Specification introduced the ability to create and use custom tags in JavaServer Pages (JSP). Custom tags are an excellent way to abstract the complexity of business logic from the presentation of Web pages in a way that is easy for the Web author to use and control. You can use custom JSP tag extensions in JSP pages to generate dynamic content, and you can use a variety of Web development tools to create the presentation.

WebLogic Server fully supports the tag extension mechanism described in the JSP 1.1 Specification.

The following sections provide an overview of JSP tag extensions:


Overview of Custom Tag Functionality

You write a custom JSP tag by writing a Java class called a tag handler. You write the tag handler class by doing one of the following:

Extending an abstract base class relieves the tag handler class from having to implement all methods in the interfaces and also provides other convenient functionality. The TagSupport and BodyTagSupport classes implement the Tag or BodyTag interfaces and are included in the API.

One or more custom JSP tags can be included in a Tag Library. A tag library is defined by a Tag Library Descriptor (TLD) file. The TLD describes the syntax for each tag and ties it to the Java classes that execute its functionality.


Using Custom Tags in a JSP

Custom tags can perform the following tasks:

Formatting Custom Tags

The format of a custom tag format can be empty, called an empty tag, or can contain a body, called a body tag. Both types of tags can accept a number of attributes that are passed to the Java class that implements the tag. For more details, see Handling Exceptions within a Tag Body.

An empty tag takes the following form:

<mytaglib:newtag attr1="aaa" attr2="bbb" ... />

A body tag takes the following form:

<mytaglib:newtag attr1="aaa" attr2="bbb" ... >

A tag body can include more JSP syntax, and even other custom JSP tags that also have nested bodies. Tags can be nested within each other to any level. For example:

<h2>This is the body of tagA</h2>
You have seen this text <mytaglib:counter /> times!
<mytaglib:repeater repeat=4>
<p>Hello World!

The preceding example uses three custom tags to illustrate the ability to nest tags within a body tag. The tags function like this:

Some Example Scenarios

The following scenarios demonstrate what you can do with custom tags:


Referencing a Tag Library

JSP tab libraries are defined in a tag library descriptor (tld). To use a custom tag library from a JSP page, reference its tag library descriptor with a <%@ taglib %> directive. For example:

  <%@ taglib uri="myTLD" prefix="mytaglib" %>


The JSP engine attempts to find the Tag Library Descriptor by matching the uri attribute to a uri that is defined in the Web Application deployment descriptor (web.xml) with the <taglib-uri> element. For example, myTLD in the above taglib directive would reference its tag library descriptor (library.tld) in the Web Application deployment descriptor like this:



The prefix attribute assigns a label to the tag library. You use this label to reference its associated tag library when writing your pages using custom JSP tags. For example, if the library (called mytaglib) from the example above defines a new tag called newtag, you would use the tag in your JSP page like this:


For more information, see Creating a Tag Library Descriptor.


Skip navigation bar  Back to Top Previous Next