日期:2014-05-18  浏览次数:20664 次

jsp页面迭代action中的集合问题
我要在jsp页面中迭代action中的list集合应该怎么做啊我的代码如下
action中的代码
private IRoleService roleService;
private List<Role> list;
public List<Role> getList() {
return list;
}
public void setList(List<Role> list) {
this.list = list;
}
public void setRoleService(IRoleService roleService) {
this.roleService = roleService;
}
public String listRole()
{
list = roleService.listAll();
if(list != null && list.size() > 0)
{
return "list";
}
return ERROR;
}
jsp页面代码
  <table width="100%">
    <thead>
      <tr>
          <th>角色名</th>
          <th>创建时间</th>
          <th>备注</th>
          <th>操作</th>
      </tr>
    </thead>  
    <tbody>
    <s:iterator value="list">
     <tr>
      <td><s:property value="roleName"/></td>
      <td><s:property value="roleCreateDate"/></td>
      <td><s:property value="roleRemark"/></td>
      <td><s:a href="updateRole.action?id=<s:property value="id"/>">编辑</s:a>|<s:a href="deleteRole.action?id=<s:property value="id"/>">删除</s:a></td>
     </tr>
    </s:iterator> 
    </tbody>
  </table>
这样报错 !  不知道是哪里错了
  

------解决方案--------------------
1.先看看ContextMap中有没有你这个list对象,如果没有你肯定啥都取不到
2.- - 我个人感觉这个list或许需要初始化 new ArrayList() 这样一下
3.看看你struts2的配置文件,其中对应的action的result的返回值是不是list,如果不是你这里就跳转不过去
4.如果以上没问题,那就<s:debug>一下,在页面上看看valuestack中对象的内容

楼上有人也说了,iterato这个标签遍历的时候,是把其中的对象压入栈顶,而不是这个集合在栈顶
对象在栈顶的时候,你就可以直接取其中的属性

- - 暂时我就能想到这些问题.......