Aruna V

Greenhorn
+ Follow
since Mar 11, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aruna V

Ooops Bingo !
Mike , thanx pal . U are a real GEM !
its the spell after all.The attributes are fine now.
Thanx a real bunch !

v_aruna@csshome.net
19 years ago
JSP
The Html generated is as follows :
<html>

<head>
<title>Your Standard Hello World Demo</title>
</head>

<body bgcolor="#ffffff">
<hr />
NAME : Aruna
<table border = 1>
<tr><td> *****Hello -<%=userName%>- </td></tr>
<tr><td> Hello -<%=userName%>- </td></tr>
<tr>
<td>Have a nice day, "Aruna" </td>
</tr>


<tr>
<td>Have a nice day, "Aruna" </td>
</tr>


<tr>
<td>Have a nice day, "Aruna" </td>
</tr>


</table>

<hr />
</body>
</html>
If you see here.. the attribute is not replaced by its value. It is passed as a string. But the iteration alone worked and the body is repeated thrice. How is that ?
Also i tried changing the name of the attribute. The effect is all the same. The attribute passed is NULL.
19 years ago
JSP
Hi Michael,
The BodyContent is used only within doInitBody() or doAfterBody(). I needed to print my attributes that i passed. Not my Body content. I am able to print any attributes passed as Body Content.
The Part :
<sample:sampletest name="<%=userName%>" iter = '3'> is not working.
The Body of the JSP :
<tr>
<td>Have a nice day, "<%=userName%>" </td>
</tr> seems to work fine !!!
Revert back please
19 years ago
JSP
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 ]
19 years ago
JSP
There was no error message. The attribute sent a NULL to my servlet. And my Servlet printed the null value on to the page through out.println .
The same tag given in the body field seemed be printed.
<html>
<%
userNAME=request.getParameter("name1");
%>
<body bgcolor="#ffffff">
<hr />
<sample:sampletest name="<%= userNAME %>" iter='3'>
<tr>
<td>"<%= userNAME %>"</td> </tr>
</sample:sampletest>
<hr />
</body>
</html>

Also both single and double quotes seems to work . There isint any difference.
19 years ago
JSP
Nope !
Does not work . I tried both single and double quotes !
19 years ago
JSP
No reply Guys ?? I am still calling for SOS !
19 years ago
JSP
My Tag details looks like this
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>
and my JSP File looks like this..
<%@ taglib uri="/sample1" prefix="sample" %>
<%!
String userNAME = null;
%>
<html>

<%
userNAME=request.getParameter("name1");
%>
<body bgcolor="#ffffff">
<hr />
<sample:sampletest name='<%= userNAME %>' iter='3'>
<tr>
<td>Have a nice day </td></tr>
</sample:sampletest>

<hr />
</body>
</html>
I hope this helps. If i give the same parameter 'userNAME' in my body tags ..it seems to work. But not as an attribute ! Please explain .
-A-
[ March 11, 2002: Message edited by: Aruna V ]
19 years ago
JSP
Hi all,
I ve a problem with jsp tags.
I ve defined my attributes in my JSP file..which is :
<%@ taglib uri="/sample1" prefix="sample" %>
<sample:sampletest name='<%= NAME %>' iter = '3'>
and my TLD for the attributes are like :
<attribute>
<name>name</name>
<required>true</required> <rtexpvalue>true</rtexpvalue>
</attribute>
irrespective of whether i put true/false for the required and rtexpvalue tags in my TLD file, the attribute name is not set. Can you tell me what might be the problem.
The problem is an example given in
http://www.onjava.com/pub/a/onjava/2000/12/15/jsp_custom_tags.html?page=2
This example is not working if we exactly follow all the steps given to develop a tag library with attribute and body .
Please help !!
v_aruna@csshome.net
19 years ago
JSP