Ok i will paste my entire code once again .
1. index.html
<html>
<head>
<title> Using Body Contenet </title>
</head>
<body>
<form name="form1" action = "jsp/sample1.jsp" method = get>
NAME: <input type="text" name="name1" value="Aruna">
<input type="Submit" name="Submit" value="Submit">
</form>
</body>
</html>
2. sample1.jsp
<%@ taglib uri="/sample1" prefix="sample" %>
<%!
String userName = null;
%>
<html>
<head>
<title>Your Standard Hello World Demo</title>
</head>
<%
userName=request.getParameter("name1");
//out.println("userName : " +java.util.date());
%>
<body bgcolor="#ffffff">
<hr />
NAME : <%= userName %>
<sample:sampletest name="<%=userName%>" iter = '3'>
<tr>
<td>Have a nice day, "<%=userName%>" </td>
</tr>
</sample:sampletest>
<hr />
</body>
</html>
3. my Tag Library Descriptor (sample1.tld)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>sample1</shortname>
<info>test sample1</info>
<uri>/sample1</uri>
<tag>
<name>sampletest</name>
<tagclass>test.Sample1</tagclass>
<bodycontent>JSP</bodycontent>
<uri>/sample1</uri>
<info>
This is a simple hello tag.
</info>
<attribute>
<name>name</name>
<required>true</required>
<rtexpvalue>true</rtexpvalue>
</attribute>
<attribute>
<name>iter</name>
<required>true</required>
<rtexpvalue>true</rtexpvalue>
</attribute>
</tag>
</taglib>
4. My servlet code : Sample1.java
package test;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class Sample1 extends BodyTagSupport
{
private String name;
private int iteration;
public void setName(String value){
System.out.println("value: " + value);
name = value;
}
public String getName(){
return(name);
}
public void setIter(String s1)
{
try
{
this.iteration = Integer.parseInt(s1);
}
catch(NumberFormatException nfe)
{
iteration = 1;
}
}
public String getIter()
{
return(Integer.toString(iteration));
}
public int doStartTag() throws JspTagException
{
try
{
JspWriter out = pageContext.getOut();
out.println("<table border = 1>");
out.println("<tr><td> *****Hello -" + name + "- </td></tr>");
if (!name.toString().equals(null))
out.println("<tr><td> Hello -" + name + "- </td></tr>");
else
out.println("<tr><td> Hello World </td></tr>");
}
catch(Exception e)
{
throw new JspTagException("Exception from doStart" + e);
}
return EVAL_BODY_TAG;
}
public int doEndTag() throws JspTagException
{
try
{
JspWriter out = pageContext.getOut();
out.println("</table>");
}
catch(Exception e)
{
throw new JspTagException("Exception from doStart" + e);
}
return EVAL_PAGE ;
}
public int doAfterBody() throws JspTagException
{
if (iteration-- >= 1)
{
BodyContent body = getBodyContent();
try
{
JspWriter out = body.getEnclosingWriter();
out.println(body.getString());
body.clearBody();
}
catch(Exception ioe)
{
throw new JspTagException("Error in Hello tag doAfterBody " + ioe);
}
return(EVAL_BODY_TAG);
}
else
{
return(SKIP_BODY);
}
}
}
5. My Web.XML File
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
<description>
Example web application illustrating the use of tags in the
"utility" custom tag library, from the JAKARTA-TAGLIBS project.
</description>
<taglib>
<taglib-uri>
/sample1
</taglib-uri>
<taglib-location>
/WEB-INF/sample1.tld
</taglib-location>
</taglib>
</web-app>
Hope this helps
[ March 17, 2002: Message edited by: Aruna V ]