日期:2014-05-19  浏览次数:20602 次

<s:iterator ... >使用的例子,STRUTS2.新手,求指教!
ACTION:
........
public String execute() throws Exception {

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rst = null;
@SuppressWarnings({ "unchecked", "rawtypes" })
Map<String, String> request = (Map) ActionContext.getContext().get(
"request");

String rets = "";
int i = 0;

conn = (Connection) ConnDemo.getConnections();
String sqls = "select * from domaininfo where state='0'";// 0,有效,1,无效
pstmt = (PreparedStatement) conn.prepareStatement(sqls);
rst = pstmt.executeQuery();

while (rst.next()) {
i++;
setDomain(rst.getString("domain"));
setBuyby(rst.getString("buyby"));
setMagurl(rst.getString("magurl"));
setPrice(rst.getString("price"));
setBelongs(rst.getString("belong"));
setContest(rst.getString("contest"));
setRegdate(rst.getString("regdate"));
setEnddate(rst.getString("enddate"));

resultList.add(domain);
resultList.add(buyby);
resultList.add(magurl);
resultList.add(price);
resultList.add(belongs);
resultList.add(contest);
resultList.add(regdate);
resultList.add(enddate);
//System.out.print(i);
}

if (i == 0) {
request.put("errorstr", "nodates");
rets = ERROR;
} else {
rets = SUCCESS;
}
//System.out.print(i);//test
//System.out.print(resultList);//test

return rets;
}
List<String> resultList = new ArrayList<String>();
public List<String> getResultList() {
return resultList;
}
public void setResultList(List<String> resultList) {
this.resultList = resultList;
}
..........
============== jsp ===============
</s:else>
  <td width="" height=""><s:property value="#L.index+1"/></td>
  <td width="" height=""><s:property value="domain"/></td>
<td width="" height=""><s:property value="buyby"/></td>
<td width="" height=""><s:property value="magurl"/></td>  
<td width="" height=""><s:property value="price"/></td>
<td width="" height=""><s:property value="belongs"/></td>
<td width="" height=""><s:property value="contest"/></td>
<td width="" height=""><s:property value="regdate"/></td>
<td width="" height="">"<s:property value="enddatec"/></td>
<td width="" height="">操作</td>
  </tr>
  </s:iterator> 
=========结果===========
结果就是循环显示了最后一条记录,而且循环了96次(共12条记录)

------解决方案--------------------
<s:iterator value="#request.postedjobList" var="job" >
<tr style="font-size: 11px;" id="job_post_tr_<s:property value="#job.jobid" />" class="appendrow">
<td width="5%" style="position: relative;" valign="middle" align="center" style="" id="<s:property value="#job.jobid" />" cla