<title section="Resin : JSP Tutorial : ">Empty Tag</title>

<ul>
<li>Client JSP using the taglib
<li>Tag class definition (HelloTag.java)
<li>Tag configuration (hello.tld)
</ul>

<subsection title="Using a taglib">

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

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

<example title="hello.jsp">
<example>
&lt;%@ taglib prefix="ct" uri="WEB-INF/hello.tld" %>
Message: &lt;ct:hello/>
</example>
<result>
Message: hello, world
</result>
</example>

</subsection>

<subsection title="Defining the tag">

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

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

<example title="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;
  }
}
</example>

</subsection>

<subsection title="Configuring the tag">

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

<example title="WEB-INF/hello.tld">
&lt;taglib>
  &lt;tag>
    &lt;name>hello&lt;/name>
    &lt;tagclass>test.HelloTag&lt;/tagclass>
  &lt;/tag>
&lt;/taglib>
</example>

</subsection>
