问答详情
源自:3-9 JSTL标签之forEach标签(下)

jstl循环遍历逆向输出

怎么逆向输出值

提问者:NightKNigth 2017-08-27 13:14

个回答

  • 慕粉3803878
    2017-08-29 16:29:05
    已采纳

    User user=new User();
    user.setName("袁冻");
    user.setAge(1);
    User user1=new User();
    user1.setName("李好");
    user1.setAge(2);
    User user2=new User();
    user2.setName("陈馨");
    user2.setAge(3);
    List<User> list=new ArrayList();

    list.add(user0);

    list.add(user1);
    list.add(user2);
    request.setAttribute("list",list);


    <c:set var="startIndex" value="${fn:length(list)-1 }"></c:set>
    <c:out value="${startIndex}"></c:out>
    <c:forEach var="i" begin="0" end="${list.size()}" varStatus="status">
      <c:out value="${list[startIndex-status.index].age}"></c:out>
    </c:forEach>