A custom tag that has neither attributes nor body content. : Tag « JSP « Java

A custom tag that has neither attributes nor body content.

/// Empty Tag
   <!-- this must be added to the web application's web.xml -->


// create File:java2s.tld in the /WEB-INF/
<!DOCTYPE taglib
  PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"

    <!-- a tab library descriptor -->
<taglib xmlns="http://java.sun.com/JSP/TagLibraryDescriptor">
  <short-name>Java2s Simple Tags</short-name>

  <!-- this tag just outputs some text -->

//compile the following code into WEB-INF\classes\com\java2s
package com.java2s;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class EmptyTag extends TagSupport
  public int doStartTag() throws JspException
      pageContext.getOut().print("in EmptyTag.doStartTag()");
    catch (IOException e) 
      System.out.println("Error in EmptyTag.doStartTag()");
      throw new JspException(e); // throw the error to the error page (if set)
    } // end of try-catch

    return SKIP_BODY;

// start comcat and load the following jsp page in browser

<%@ taglib uri="/java2s" prefix="java2s" %>

    <title>A custom tag: empty</title>
    This page uses a custom tag that has neither attributes nor body content.
    Here is its output:
    <h1><java2s:emptyTag /></h1>


Related examples in the same category

1.Your own simple JSP tag
2.Create your own tag: a custom tag body
3.A custom tag: empty with attributes
4.A custom tag: scripting variable
5.Write your own tag
6.Logo Tag
7.A custom tag: empty
8.Tag lifecycle with Attribute
9.A custom tag: iteration
10.JSP Simple Tags
11.JSP tag: advanced tagsJSP tag: advanced tags
12.JSP classic tagsJSP classic tags
13.JSP Tag Libraries and JSTLJSP Tag Libraries and JSTL
14.JSP Directives: HTML tag