Cannot create iterator for this collection高手请进
运行环境:jdk1.5.0_04 && Struts 1.3
后台Bean
package department;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.db.ConnDB;
public class DepartmentBean {
private Connection conn = null;
private Statement stmt = null;
public DepartmentBean() throws Exception {
this.conn = new ConnDB().ds.getConnection();
}
public ArrayList getDepartments() throws Exception {
ArrayList<Department> ret = new ArrayList<Department>();
try {
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from fare");
while (rs.next()) {
Department temp = new Department();
temp.setFareID(rs.getString("fareID"));
temp.setFareName(rs.getString("fareName"));
temp.setFareAddress(rs.getString("fareAddress"));
temp.setFarePhone(rs.getString("farePhone"));
temp.setFareManager(rs.getString("fareManager"));
temp.setFareDescription(rs.getString("fareDescription"));
ret.add(temp);
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
}
return ret;
}
}
Department类就是set和get方法.
jsp
<%@ taglib uri="/struts-html" prefix="html" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="department.Department"%>
<jsp:useBean id="departmentBean" class="department.DepartmentBean" scope="session"/>
<c:set var="departments" value="${departmentBean.departments}"/>
<%-- used for test
<%ArrayList collection = departmentBean.getDepartments();%>
<%Department dep = (Department)collection.get(2);%>
<%System.out.println(dep.getFareName());%>
--%>
......
<table name="testTable">
<logic:iterate id="depts" name="departments">
<tr>
<td>
<bean:write name="depts" property="empName"/>
</td>
</tr>
</logic:iterate>
</table>
报错:Cannot create iterator for this collection
请高手帮忙///