struts2怎样遍历list显示在前台页面
action是这样
private List<Person> list;
public List<Person> getList() {
return list;
}
public void setList(List<Person> list) {
this.list = list;
}
req.setAttribute("list", list);
if(list==null)
return "error";
else
return "success";
前台jsp
<s:iterator id="stat" value="list" status="st">
<s:property value="username[0]"/>
<s:property value="password[#st.index][0]"/>
</s:iterator>
该怎么改呢
------解决方案--------------------你的代码有点看不懂啊,req?request? list怎么来的。是request传值的?
我给下我的
public class ShowMissionAction {
private List<ExpirementMission> missions=new ArrayList<ExpirementMission>();
public List<ExpirementMission> getMissions() {
return missions;
}
public void setMissions(List<ExpirementMission> missions) {
this.missions = missions;
}
public String showDistributionMission(){
System.out.println("-- show distribution missions now --");
Map<String, Object> session = ActionContext.getContext().getSession();
analysist =(Employee) session.get("analysist");
session.put("name", analysist.getName());
missions=analysistMissionService.showDistributionMissions(analysist);
System.out.println(analysist.getName()+","+missions);
session.put("missions_state", "distribution");
if(missions.isEmpty()){
session.put("haveMission", "NO");
}else{
session.put("haveMission", "YES");
}
return "SUCCESS";
}
}
jsp 代码:
<s:iterator value="missions" status="i">
<tr>
<td><s:property value="batchNumber" /></td>
<td><s:property value="sort" /></td>
<td><s:property value="serialNumber" /></td>
<td><s:property value="batchNumber" /></td>
<td><s:property value="expriement" /></td>
</tr>
</s:iterator>
附:
<s:iterator id="stat" value="list" status="st"> 中id是web,html标签元素
至于req.setAttribute("list", list); 多余了,在struts2中,只需有list bean 且有setter/getter方法,struts标签能自动获取,因为值放在了ActionContext中,struts2特有的一块内存区域
------解决方案--------------------附加 missions的bean:
package com.until.temporay;
import java.sql.Date;
import&