Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Sunday, December 2, 2007

java code for A custom tag that has neither attributes nor body content

/// Empty Tag



/java2s
/WEB-INF/java2s.tld


// create File:java2s.tld in the /WEB-INF/
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">



1.0
1.2
Java2s Simple Tags



emptyTag
com.java2s.EmptyTag
empty



//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
{
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="/java2s" prefix="java2s" %>



A custom tag: empty


This page uses a custom tag that has neither attributes nor body content.
Here is its output:



No comments: