문제

I am trying to associating this two arraylist and print..

            <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>

i want to print "comment" with "comment time" that are the values of two different arraylists but this code is printing whole first arraylist and then second one.

any hint???!

도움이 되었습니까?

해결책

You have to use varStatus attribute to get the current index, and print elements from both arraylists at that index (this is of course assuming that both arraylists contains same number of elements):

<c:forEach items="${postitem.comment}" var="comment" varStatus="status">
    <span>comment="${comment}" </span>
    <span>comment_time="${postitem.commenttime[status.index]}"  </span>
</c:forEach>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top