Separate item in foreach tag (jstl)

2019-02-21 07:09发布

I have a JSP page with JSTL and I want to separate an user from other with an <hr> tag. How can I solve it?

<c:forEach var="user" items="${list_users}">    
    <c:out value="${user.name}"/>
    <c:out value="${user.surname}"/>
</foreach>

标签: java jsp jstl el
2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-21 07:59

You can use a table to draw each user in the cell, then put <hr>

<table>
<c:forEach var="user" items="${list_users}">  
<tr><td>  
 <c:out value="${user.name}"/><br>
 <c:out value="${user.surname}"/><br>
<hr>
</td></tr>
</c:foreach>
</table>
查看更多
太酷不给撩
3楼-- · 2019-02-21 08:02

Put it inside the loop and use varStatus attribute of c:forEach to remove the one line you don't need in the end.

<c:forEach var="user" items="${list_users}" varStatus="status">
  <c:out value="${user.name}" />
  <c:out value="${user.surname}" />
  <c:if test="${not status.last}">
    <hr />
  </c:if>
</c:forEach>
查看更多
登录 后发表回答