Contents | Prev | Next



Simple Tags


Tag Handlers

The handler for a simple tag must implement the doStartTag and doEndTag methods of the Tag interface. The doStartTag method is invoked when the start tag is encountered. This method returns SKIP_BODY because a simple tag has no body. The doEndTag method is invoked when the end tag is encountered. The doEndTag method needs to return EVAL_PAGE if the rest of the page needs to be evaluated; otherwise it should return SKIP_PAGE.

The following simple tag:

<tlt:simple />
would be implemented by the following tag handler:

public SimpleTag extends Tag Support {
   public int doStartTag() throws JspException {
      try {
         pageContext.getOut().print("Hello.");
      } catch (Exception ex) {
         throw new JspTagException("SimpleTag: " + 
            e.getMessage());
      }
      return SKIP_BODY;
   }
   public int doEndTag() {
      return EVAL_PAGE;
   }
}

TLD bodycontent Element

Tags without bodies must declare that their body content is empty:

<tag>
   ...
   <bodycontent>empty</bodycontent>
</tag>


Contents | Prev | Next
Copyright © 2000 Sun Microsystems, Inc. All rights reserved.