Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Sunday, December 2, 2007

java code for A custom tag: empty




/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




tagLifecycle
com.java2s.TagLifecycle
empty

attr1


attr2




//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.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

/* This tag handler outputs information about when different methods
are called.
*/

public class Lifecycle extends TagSupport
{
// Constructor

public Lifecycle()
{
System.out.println("constructor called");
}

// Methods inherited from TagSupport

public void setPageContext(PageContext p)
{
super.setPageContext(p);
System.out.println("setPageContext() called");
}

public void setParent(Tag t)
{
super.setParent(t);
System.out.println("setParent() called");
}

public void release()
{
System.out.println("release() called");
}

// Code to implement the "attr1" attribute

private String attr1;
public String getAttr1()
{
return attr1;
}
public void setAttr1(String s)
{
System.out.println("setAttr1() called with value " + s);
attr1 = s;
}

// Code to implement the "attr2" attribute

private String attr2;
public String getAttr2()
{
return attr2;
}
public void setAttr2(String s)
{
System.out.println("setAttr2() called with value " + s);
attr2 = s;
}
public int doStartTag() throws JspException
{
System.out.println("doStartTag() called");

return SKIP_BODY;
}

public int doEndTag() throws JspException
{
System.out.println("doEndTag() called");
return super.doEndTag();
}
}



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

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



A custom tag: empty





Check your Tomcat console window for the output

No comments: