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

100分继续问标签的问题
我在Action里边,写了2个不同的代码。
hashMap和list

for   (Iterator   i   =   list1.iterator()   ;   i.hasNext()   ;){
list3.add(i.next());
}

for   (Iterator   i   =   list2.iterator()   ;   i.hasNext()   ;){
dcMap.put( "dm ",   i.next());
}

请看一下下边的写的对么?
如果我想在页面上将这2个的内容显示出来。应该怎样用struts的logic标签写?

谢谢大家

------解决方案--------------------
struts 有一个 iterator 的tag,
<logic:iterator id = XXX name=XXX>
 XXX
</logic:iterator>

具体可以网上找现成的例子
------解决方案--------------------
在action中把从数据库查出来的集合放到request中,如
List user = UserDao.getAllUser();
request.setAttribute( "allUser ", user);

在页面中用标签循环出来,如
<logic:iterate name= "allUser " id= "user ">
<tr>
<td> <bean:write name= "user " property= "name "/> </td>
....................省略
</tr>
</logic:iterate>
------解决方案--------------------
首先list是比较简单的:
第一中情况:我在后台用request.setAttribute( "scoreList ",list);然后我就可以在页面上遍利 <logic:iterate id= "aa " name= "scoreList " scope= "request ">
<bean:write name= "aa "/>
</logic:iterate>
id的值自己定但必须和 <bean:write> 的name一致,scope可以不写.
第二种情况:list是javabean里的一个属性;request.setAttribute( "stu ",student);页面就用 <logic:iterate id= "aa " name= "stu " property= "scoreList ">
<bean:write name= "aa "/>
</logic:iterate>

而map的话,有点不同: request.setAttribute( "stuMap ",map);
<logic:iterate id= "aa " name= "stuMap ">
<bean:write name= "aa " property= "key "/> //得到键
<bean:write name= "aa " property= "value "/> //得到值
</logic:iterate>

这些是基础的,楼主应该自己学习下.
------解决方案--------------------
在form中定义一个List list,把值取出来放在list中,
<logic:iterator id= "test " name= "form名称 " index= "indexId " property= "list ">
<bean:write name= "test " property= "存在list中的bean的属性 "/>
</logic:iterator>