Empty Tag
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
JSP Compilation
Reference
Tutorials
Articles
FAQ

JSP Page Creation
Request
Topics
Tag Libraries

Tag Reuse
Hello Tag
Tag Attributes
Mail Tag
Tag Files
Tag Reuse
Tag Libraries
Tag Attributes

The simplest kind of tag does not evaluate it's contents.

  1. Using a taglib
  2. Defining the tag
  3. Configuring the tag

Using a taglib

Using a taglib in a JSP file has two steps. First, the JSP needs to define the prefix and the tld (tag library descriptor) for the tag.

Normally, JSP copies bytes from the .jsp to the browser without interpreting it. The taglib directive tells the JSP engine to treat elements starting with the prefix as JSP extension tags.

hello.jsp
<%@ taglib prefix="ct" uri="WEB-INF/hello.tld" %>
Message: <ct:hello/>

Message: hello, world

Defining the tag

Many simple tags can just extend TagSupport. The hello tag implements doStartTag. When the hello tag starts, the JSP will execute doStartTag. In this case, it'll print "hello, world".

Since the content of the hello tag doesn't matter, HelloTag returns SKIP_BODY. Empty tags will generally return SKIP_BODY.

HelloTag.java
package test;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag extends TagSupport  {
  public int doStartTag() throws JspException
  {
    try {
      pageContext.getOut().println("hello, world");
    } catch (IOException e) {
    }
    
    return SKIP_BODY;
  }
}

Configuring the tag

Finally, you need to configure the tag in a .tld (tag library descriptor) file. The .tld matches the tag name hello with the tag class test.HelloTag.

WEB-INF/hello.tld
<taglib>
  <tag>
    <name>hello</name>
    <tagclass>test.HelloTag</tagclass>
  </tag>
</taglib>


Tag Reuse
Tag Libraries
Tag Attributes
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.