简体   繁体   中英

JSP Operations in Html Code

I have a issue like i am getting list from Controller to JSP page. When i use the following code the data prints as continous in a single line.

<table>
<tr>
<c:forEach var="a" items="${list}">
    <td>${a}</td>
</c:forEach>
</tr>
</table>

Consider the situation like the list size can be anything. I need to display the elements in a tabular way like first 10 elements in first row, next 10 elements in second and so on by using JSP and HTML code. Any Help would be great. Thank You.

You can do that using c:if and the loop iterator index:

<c:forEach var="a" items="${list}" varStatus="it">
 <c:if test="${it.index%10==0}">
  <tr>
 </c:if>
 <td>${a}</td>
 <c:if test="${it.index%10==9}">
  </tr>
 </c:if>
</c:forEach>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM