现在有一个list集合,里面存放的是map(list里面大概放了50个map元素),map里面的内容是<1,"xx">的形式(每个map里面放了大概100条这样的数据),请教各位怎么把这个list里面的元素在jsp页面展示出来?最好能用struts2.0的标签实现,用其他标签也行,谢谢各位了。

解决方案 »

  1.   

    <logic:present   name= "list "> 
     <logic:iterate   name= "list "     id= "map"   scope= "request ">  
       <bean:write   name= "map " property= "mapkey"/>    
     </ogic:iterate>
    </logic:present>
    可能是这样写,没试过哦。
      

  2.   

    这个俺 常用。
    <table>
    <s:iterator value="list">
    <tr>
         <td><s:property value="1"></td>
         <td><s:property value="2"></td>
         <td><s:property value="3"></td>
    </tr>
    </s:iterator>
    </table>这是大概意思,我机器调不了,
    list  是你的上下文中存的List对象的名字,1,2,3是你map 的key
      

  3.   

    <s:iterator value="list" var="list">
    </s:iterator>
      

  4.   

    使用Struts2的标签的话,可以简化一点难度,下面的方案只是一个大致的思路,需要LZ自己进一步去调试:假设LZ所说的list保存在request范围内,名称为reqList。界面代码如下:
    <s:iterator value="#request.reqList" id="lstMap">
        <s:iterator value="lstMap" id="mapElement">
            <s:property value='key'/>
            <s:property vlaue='value'/>
        </s:iterator>
    </s:iterator>
      

  5.   

    出现诸如 List<Map<K, V>>、Map<K, Map<K, V>> 等等此类结构的代码的话,这样的代码写得并不好,建议重新设计。
      

  6.   

    谢谢楼上几位,我在两个框架下,一个是struts1.0,另一个是struts2.0,分别按你们说的方法试过了,还是不行。
    要求是这样的:给一张表,表中有50个字段,注意是50个字段,并且这张表没有id,里面大概有100条数据,要求把数据取出来展示到jsp页面上,jsp页面要求自己写。数据取出来不难,难的是怎么在页面展示出来,我实在是想不到更好的设计方式了才把数据放到map里用list的,你看了之后能给出比较好的设计吗?谢谢了
      

  7.   

    struts的标签  <nested-el:iterate property="list">
      <li><a href=""><nested-el:write property="字段名"/></a></li>
      </nested-el:iterate>
    或者JSTL的标签 <c:forEach items="${list}" var="list">
              <li>${list.字段名}</li>
              </c:forEach>
      

  8.   


    <logic:iterator id="bean" name="list" scope="request">
    ${bean.属性}
    </<logic:iterator >
     这么麻烦,直接这样
    这跟ID有什么关系?
      

  9.   

    请楼主将 struts标签 从头到尾在看一遍,只需要10分钟吧!!!!!
      

  10.   


    我在eclipse里面测试过了,原先的代码需要小修改一下,修改后如下:<s:iterator value="reqList" id="lstMap">
        <s:iterator value="lstMap" id="mapElement">
            <s:property value='key'/>
            <s:property value='value'/>
        </s:iterator>
    </s:iterator>以上红色部分是修改的内容,已测试证明代码是可行的,请LZ再试试。
      

  11.   


    CSDN的论坛显示有些问题,只能将代码再贴一下了:以下是界面的代码:<s:iterator value="reqList" id="lstMap">
        <s:iterator value="lstMap" id="mapElement">
            <s:property value='key'/>
            <s:property value='value'/>
        </s:iterator>
    </s:iterator>以下是action的部分代码,用来生成list和map,注意其属性reqList的名称与上面代码的对应:public class HelloWorld extends ExampleSupport {

    public List<Map> reqList = new ArrayList<Map>(); public List<Map> getReqList() {
    return reqList;
    } public void setReqList(List<Map> reqList) {
    this.reqList = reqList;
    } public String execute() throws Exception {
            setMessage(getText(MESSAGE));
            
            Map[] myMap = new HashMap[50];
            
            for (int i=0; i<50; i++) {
             myMap[i] = new HashMap<Integer,String>();
            
             for(int j=0; j<100; j++) {
            
             myMap[i].put(j, i+"map"+j);
             }
            
             reqList.add(myMap[i]);
            }
            
            return SUCCESS;
        }
    ……