简体   繁体   中英

how to use struts2 tag to traversal a Map<Object,String> in 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>

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.

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 a map with a key which is custom object is very annoying thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM