当前位置: 代码迷 >> Java Web开发 >> s:iterator 迭代不出数据解决思路
  详细解决方案

s:iterator 迭代不出数据解决思路

热度:3087   发布时间:2013-02-25 21:22:05.0
s:iterator 迭代不出数据
在action中调用方法list

public String list() {

wcList = inventoryManager.listWoodCategory();

Iterator it = wcList.iterator();
while (it.hasNext()) {
WoodCategory wc = (WoodCategory) it.next();
logger.warn(wc.getName());
}
logger.warn("list excuted!");

return SUCCESS;
}


可以打印出值。

2012-4-25 0:07:51 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/hongmu] is completed
18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - reeerer
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - 不需要
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - 我
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - 8
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - rtrtrtrt454
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - rt
 18858 [http-bio-8080-exec-36] WARN com.wxh.action.WoodCategoryAction - list excuted!
 25013 [http-bio-8080-exec-33] WARN com.wxh.service.impl.InventoryManagerImpl - 保存木材种类成功


在jsp页面中显示不出值

jsp代码是这样写的:
<table>
<tr>
<th>Name</th>

</tr>
<s:iterator value="wcList">
<tr>

<td><s:property value="name" /></td>

</tr>
</s:iterator>
</table>


求助:s:iterator代码应该如何写才能迭代出值?

------解决方案--------------------------------------------------------
<s:iterator value="#request.wcList" var="wc">
<tr>

<td><s:property value="#wc.name" /></td>

</tr>
</s:iterator>
------解决方案--------------------------------------------------------
你的wcList都没放入request中,而且struts2标签也写错了。。

request.setAttribute("wcList",wcList);



<s:iterator id="list" value="#request.wcList">
<s:property value="list.name"/>
</s:iterator>
------解决方案--------------------------------------------------------
<s:iterator value="wcList" id="wc">
<tr>

<td><s:property value="name" /></td>

</tr>
</s:iterator>
加个id,并且要确认,该wclist有getter方法

------解决方案--------------------------------------------------------
检查下有没有get和set方法。
------解决方案--------------------------------------------------------
探讨

to xiaoxiaojunjie
action中get set方法都有,上加<s:debug> 标签后显示下面的东东,我还不清楚是什么,请再指点!

[Debug]
Name
ObjectProperty NameProperty Value
com.wxh.model.WoodCategory id -1
name null
com.wxh.action.WoodC……

------解决方案--------------------------------------------------------
Java code
<s:iterator value="wcList" var="list">        ${list.name }    </s:iterator>
  相关解决方案