【问题标题】:associating two ArrayList in JSP在 JSP 中关联两个 ArrayList
【发布时间】:2014-05-01 11:55:13
【问题描述】:

我正在尝试关联这两个数组列表并打印..

            <c:when   test="${postitem.posttype.equals('text')}">
                <h5>id="${postitem.postid}"</h5> 
                <pre>  ${postitem.postdata}  </pre>
                <span>datetime="${postitem.posttime}</span>
                <c:forEach items="${postitem.comment}" var="comment">
                    <span>comment="${comment}" </span>
                </c:forEach>
                <c:forEach items="${postitem.commenttime}" var="comment_time">
                    <span>comment_time="${comment_time}"  </span>
                </c:forEach>
            </c:when>

我想打印带有“comment time”的“comment”,它们是两个不同数组列表的值,但是这段代码打印的是整个第一个数组列表,然后是第二个。

任何提示???!

【问题讨论】:

    标签: java jsp arraylist jstl


    【解决方案1】:

    您必须使用varStatus 属性来获取当前索引,并在该索引处打印两个数组列表中的元素(这当然是假设两个数组列表包含相同数量的元素):

    <c:forEach items="${postitem.comment}" var="comment" varStatus="status">
        <span>comment="${comment}" </span>
        <span>comment_time="${postitem.commenttime[status.index]}"  </span>
    </c:forEach>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-14
      • 2013-04-30
      • 2014-01-31
      • 2018-02-03
      • 1970-01-01
      • 2015-10-29
      • 2016-03-31
      相关资源
      最近更新 更多