如何使用struts2标记遍历Map< Object,String>在jsp中 [英] how to use struts2 tag to traversal a Map<Object,String> in jsp
问题描述
如何使用Struts2标记在JSP中遍历Map<Course,String>
.
Course
是一个类.它具有三个属性.它们是String coursename
,int courseid
,String courseType
.我在项目中使用Struts2.该操作将Map<Course,String>
返回给JSP.
我用
How to use Struts2 tag to traversal a Map<Course,String>
in JSP.
Course
is a class. It has three attributes. They are String coursename
, int courseid
, String courseType
. I use Struts2 in my project. The Action returns the Map<Course,String>
to JSP.
And I use
<s:iterator value="cmap" status="st">
<tr><td>
<s:iterator value='key'><s:property value="key.coursename"/></s:iterator> </td>
<td><s:property value='value'></s:property></td></tr>
</s:iterator>
它可以在JSP中打印正确的String值.但是它不能打印课程类型"数据! 怎么解决呢?我是新手.
It can print the right String value in JSP. But it cannot print the Course Type data! How to solve it? I am a novice.
推荐答案
您不需要第二个迭代器即可获取Course
数据.只需使用key
即可获取值.
You do not need second iterator to get Course
data. Just use key
to get your values.
<s:iterator value="cmap">
<tr>
<td><s:property value="key.coursename"/></td>
<td><s:property value="value"/></td>
</tr>
</s:iterator>
BTW带有自定义对象键的地图是一件很烦人的事.
BTW a map with a key which is custom object is very annoying thing.
这篇关于如何使用struts2标记遍历Map< Object,String>在jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!