//TagHandlerForm.jsp <%@ taglib uri="/roseindia.tld" prefix="roseindia" %> Your Standard Hello World Demo
//when the name is null then, it will display hello world //roseindia.tld 1.0 1.1 roseindia roseindia Sample Tag library hello TLD.Hello empty This is a simple hello tag. name false iterations false //Hello.java package TLD; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; public class Hello extends BodyTagSupport { private String name=null; private int iterations=1; public void setName(String value){ name = value; } public String getName(){ return(name); } public void setIterations(String value){ try { iterations = Integer.parseInt(value); } catch(NumberFormatException nfe) { iterations = 1; } } public String getIterations(){ return(Integer.toString(iterations)); } /** * doStartTag is called by the JSP container when the tag is encountered */ public int doStartTag() { try { JspWriter out = pageContext.getOut(); out.println(""); if (name != null){ out.println(""); } else{ out.println("");} } catch (Exception ex) { throw new Error("All is not well in the world."); } // Must return SKIP_BODY because we are not supporting a body for this // tag. return SKIP_BODY; } /** * doEndTag is called by the JSP container when the tag is closed */ public int doEndTag(){ try { JspWriter out = pageContext.getOut(); out.println("
Hello " + name + "
Hello World
"); } catch (Exception ex){ throw new Error("All is not well in the world."); } return EVAL_PAGE; } public int doAfterBody() throws JspTagException { if (iterations-- >= 1) { BodyContent body = getBodyContent(); try { // Make sure we put anything in the output stream in the // body to the output stream of the JSP JspWriter out = body.getEnclosingWriter(); out.println(body.getString()); body.clearBody(); // Clear for next evaluation } catch(IOException ioe) { throw new JspTagException("Error in Hello tag doAfterBody " + ioe); } return(EVAL_BODY_TAG); } else { return(SKIP_BODY); } } }