Mega Code Archive

 
Categories / Java / JSP
 

A custom tag that has neither attributes nor body content

/// Empty Tag    <!-- this must be added to the web application's web.xml --> <taglib>   <taglib-uri>/rntsoft</taglib-uri>   <taglib-location>/WEB-INF/rntsoft.tld</taglib-location> </taglib> // create File:rntsoft.tld in the /WEB-INF/ <!DOCTYPE taglib   PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"    "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">     <!-- a tab library descriptor --> <taglib xmlns="http://java.sun.com/JSP/TagLibraryDescriptor">   <tlib-version>1.0</tlib-version>   <jsp-version>1.2</jsp-version>   <short-name>rntsoft Simple Tags</short-name>   <!-- this tag just outputs some text -->   <tag>     <name>emptyTag</name>     <tag-class>com.rntsoft.EmptyTag</tag-class>     <body-content>empty</body-content>   </tag> </taglib> //compile the following code into WEB-INF\classes\com\rntsoft package com.rntsoft; 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   {     try      {       pageContext.getOut().print("in EmptyTag.doStartTag()");     }     catch (IOException e)      {       System.out.println("Error in EmptyTag.doStartTag()");       e.printStackTrace();       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="/rntsoft" prefix="rntsoft" %> <html>   <head>     <title>A custom tag: empty</title>   </head>   <body>     This page uses a custom tag that has neither attributes nor body content.     Here is its output:     <h1><rntsoft:emptyTag /></h1>   </body> </html>