tags:

views:

302

answers:

2

Hi,

I'm trying to display an attribute value of ArrayList from JSP set in session scope in servlet as:

 hs.setAttribute("Attr",arr); //where hs is reference to HttpSession and arr is of type of ArrayList

But when I invoked simple tag with the EL expression as optionList attribute value of advice tag in JSP as:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="mine" uri="DiceFunctions" %>


<html><body>

<mine:advice  optionList='${sessionScope.Attr}' />


</body></html>

I displayed nothing.

The code of Simple tag handler is:

package foo;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import javax.servlet.jsp.*;
import java.util.*;

public class AdvisorTagHandler extends SimpleTagSupport{
String name;
String size;
ArrayList option;

public void doTag() throws JspException,IOException{
JspWriter out=getJspContext().getOut();

for(Object o: option)
{
out.print(out.toString());

}

public void setOptionList(List value)
{
option=(ArrayList)value;


}
}

and TLD, which is set in WEB-INF folder is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">

<tlib-version>1.2</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>DiceFunctions</uri>

<tag>

<name>advice</name>
<tag-class>foo.AdvisorTagHandler</tag-class>
<body-content>empty</body-content>
<attribute>
<name>optionList</name>
<type>java.util.List</type>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

What's wrong I'm doing? How can I display the value of ArrayList object?

Thanks in advance.

+1  A: 

I think this is because your TLD specifies the JSP version as 1.2. The expression language only came in with JSP 2.0, and so the container may be explicitly disabling expressions for this tag.

Try setting jsp-version to 2.0. Also, check that your web.xml is declared as using servlets version 2.4 or higher, some containers disable features if they think an earlier servlet version is being referred to.

skaffman
I've done as you said, but it is still returning no output. I'm using Tomcat 5.5
Greenhorn
Have you tried @NirLevy's suggestion?
skaffman
Sorry, skaffman. you're absolutely correct, and sorry for my previous comment.
Greenhorn
/me is childishly offended for not having my answer marked as correct :-/
Nir Levy
+2  A: 

I think you have a simple bug in this line:

out.print(out.toString());

i think you ment

out.print(o.toString());
Nir Levy