action里面生成一个list
如resultlist
然后返回页面之前request.setAttribute("resultlist",resultlist);.jsp中<logic:iterate id="iterList" name="resultlist">
<bean:write name="iterList" property="a" />
<bean:write name="iterList" property="b" />
<%--假设resultlist每行含有a,b两个属性--%>
</logic:iterate>
如resultlist
然后返回页面之前request.setAttribute("resultlist",resultlist);.jsp中<logic:iterate id="iterList" name="resultlist">
<bean:write name="iterList" property="a" />
<bean:write name="iterList" property="b" />
<%--假设resultlist每行含有a,b两个属性--%>
</logic:iterate>
现在由rs生成了vector,为什么一样要生成list?
如果用vector怎么把值给request?
logic:iterate支持Vector.
request.setAttribute("resultlist",yourVector);
<tr>
<td><bean:write name="aczdw" property="tfdwbh" /></td>
<td><bean:write name="aczdw" property="tfqymc" /></td>
</tr>
</logic:iterate>
aczdw为Arraylist组,现在是显示的结果数正确,但是全是同一条记录,
显示的所有行都是最后一次取到的记录,
这是怎么回事呢?
我看过了,取到的是不同的记录啊,
ArrayList aczdw = new ArrayList();
while(rs.next()){
cd.setTflxr((String)rs.getString("dwbh"));
cd.setTfwz((String)rs.getString("qymc")); aczdw.add(cd);
}
request.setAttribute("aczdw",aczdw);没什么问题吧?可是怎么回事呢?在线等
<tr>
<td><bean:write name="aczdw" property="tfdwbh" /></td>
<td><bean:write name="aczdw" property="tfqymc" /></td>
</tr>
</logic:iterate>改成
<logic:iterate id="row" name="aczdw" scope="request" >
<tr>
<td><bean:write name="row" property="tfdwbh" /></td>
<td><bean:write name="row" property="tfqymc" /></td>
</tr>
</logic:iterate>
试试看
再说,我并没有定义"row",为什么要改成它呢?
while(rs.next()){
cd.setTflxr((String)rs.getString("dwbh"));
cd.setTfwz((String)rs.getString("qymc")); aczdw.add(cd);
}
request.setAttribute("aczdw",aczdw);
-- 你的代码中的cd在哪里定义的,必须在循环中定义!
while(rs.next()){
CD cd = new CD();
...
}
我估计你是在循环之前定义的,所以得到的是最后一个记录再说,我并没有定义"row",为什么要改成它呢?
-- <logic:iterate id="row" name="aczdw" scope="request" >中定义了“row”,他会生成一个新的Bean,名字为"row".