关于如何使用struts标签输出值为map的list

王朝java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

最近在一个项目中,要将一个list在客户端输出,而list里面的每个值不是bean,而是map,想好好久,想了个办法,可以实现,代码如下

ArrayList testList=new ArrayList();

HashMap testMap1=new HashMap();

testMap1.put("grade","七年级");

testMap1.put("class","一班");

testMap1.put("master","张三");

testList.add(testMap1);

HashMap testMap2=new HashMap();

testMap2.put("grade","八年级");

testMap2.put("class","二班");

testMap2.put("master","张三");

testList.add(testMap2);

HashMap testMap3=new HashMap();

testMap3.put("grade","九年级");

testMap3.put("class","五班");

testMap3.put("master","李四");

testList.add(testMap3);

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#0033CC" name="tableList">

<tr><td>master</td><td>class</td><td>grade</td></tr>

<logic:iterate id="element" indexId="ind" name="testList" >

<tr>

<td>

<logic:iterate id="elementValue" indexId="idx" name="element">

<logic:equal name="elementValue" property="key" value="master">

<bean:write name="elementValue" property="value"/>

</logic:equal>

</logic:iterate>

</td>

<td> <logic:iterate id="elementValue" indexId="idx" name="element">

<logic:equal name="elementValue" property="key" value="class">

<bean:write name="elementValue" property="value"/>

</logic:equal>

</logic:iterate>

</td>

<td><logic:iterate id="elementValue" indexId="idx" name="element">

<logic:equal name="elementValue" property="key" value="grade">

<bean:write name="elementValue" property="value"/>

</logic:equal>

</logic:iterate>

</td>

</tr>

</logic:iterate>

</table>

master

class

grade

还有更好的方法,欢迎交流,第一次在blog上发文,没有排版,请多见谅!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有