Tuesday, March 2, 2010

Custom tag

1)Create a class which extends BodyTagSupport or implements Tag

package deep;

import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;


public class Deepak extends BodyTagSupport {



BodyContent bodyContent;


public int doStartTag() throws JspException {

return EVAL_BODY_TAG;
OR
return SKIP_BODY;

}

public void setBodyContent(BodyContent
bodyContent) {
this.bodyContent = bodyContent;
}

public int doAfterBody() throws JspException {

return EVAL_BODY_TAG;
OR
return SKIP_BODY;

}

public int doEndTag() throws JspException {

return EVAL_PAGE;
}
}
//If It returns SKIP_PAGE,then code after the tag will not be executed ,in case of EVAL_PAGE it willbe calculated
2)Create tld(For ex:deep.tld)

3)Edit your web.xml

4)Add line in your JSP page
<%@ taglib uri="/WEB-INF/tag/name.tld" prefix="n" %>

and use tag which you defined earlier


5)Run your application

These are the steps which involved in making custom tag.Any suggestion or correction,plz leave comment.

Thanks
Deepak

No comments:

Post a Comment