我想在servlet作爲顯示從JSP集會話範圍的ArrayList的屬性值:簡單標籤不能intrepret會話scope屬性
hs.setAttribute("Attr",arr); //where hs is reference to HttpSession and arr is of type of ArrayList
但是當我調用簡單的標籤與EL表達式,如JSP標籤建議的optionList屬性值:
<%@ 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>
我什麼也不顯示。
簡單的標籤處理器的代碼是:
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;
}
}
和TLD,這是在WEB-INF文件夾設置爲:
<?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>
什麼是錯的,我在做什麼?我如何顯示ArrayList對象的值?
在此先感謝。
我照你說的做了,但它仍然沒有返回輸出。我正在使用Tomcat 5.5 – Greenhorn 2009-07-13 11:25:52