帮帮我啊 一天没吃饭了 在taglib中定义的类型为arraylist的脚本变量,我在JSP这样引用错在哪里了????????
tag:
import bit.sunny.actionform.SubjectBean;
public class CreateSubjectListTag extends TagSupport {
static final long serialVersionUID = 1L;
DataStore ds=null ;
ArrayList <SubjectBean> lst = null;
public int doStartTag(){
ds = DataStore.getInstance();
String sql= "select * from tbsubject ";
ResultSet rs = null;
rs = ds.read(sql);
lst = new ArrayList <SubjectBean> ();
try {
while (rs.next())
{
SubjectBean a = new SubjectBean();
a.setSubjectID(rs.getInt(1));
a.setSubjectName(rs.getString(2));
lst.add(a);
}
} catch (
SQLException e1) {
e1.printStackTrace();
}
String[] citys = new String[]{ "北京 ", "伤害 "};
pageContext.setAttribute( "citys ", citys);
return SKIP_BODY;
}
}
web.xml
<tag>
<name> CreateSubjectListTag </name>
<tag-class> bit.sunny.tags.CreateSubjectListTag </tag-class>
<variable>
<name-given> lst </name-given>
<variable-class> java.util.ArrayList </variable-class>
<declare> true </declare>
<scope> AT_END </scope>
</variable>
<variable>
<name-given> citys </name-given>
<variable-class> java.lang.String[] </variable-class>
<declare> true </declare>
<scope> AT_END </scope>
</variable>
</tag>
jsp中
<%
for(int i = 0;i < lst.size(); i++){
out.print( " <option value= "+lst.get(i).getSubjectID()+ "> "+lst.get(i).getSubjectName()+ " </option> ");
}
%>
JSP代码错在哪里了
------解决方案--------------------lz的问题好象问了两次。。。
首先需要在CreateSubjectListTag自定义标签中将ArrayList放到session中:
HttpSession session = pageContext.getSession();
String username = session.setAttribute( "array ",lst);
<