Reprinted from:
http://www.bkjia.com/webzh/880546.html;
Use C:foreach to control 5 line breaks, ForEach wrap
I have a problem with the project today, I need to display an indeterminate number of images on the Web page (the image is from the database), with the <c:forEach> loop value. You need to make a line to display a fixed number of images. The code is as follows (I'm here to control 5 rows):
<table> <c:foreach items= "${list}" var= "obj" varstatus= "status" > <c:if test= "${ Status.count eq 1 | | (status.count-1)% 5 eq 0} "> <tr> </c:if> <td> ${obj.url} <!-- URL is a property of obj- </td> <c:if test= "${status.count% 5 eq 0 | | status.count eq 5}" > </tr > </c:if> </c:forEach> </table>
Note: Status.count represents the iteration count of the current iteration starting at 1.
Solution:<c:foreach> iterates through the array of contents, and the JSP is displayed with every four newline
<c:forEach> also has a Varstatus property. Varstatus.index is to get the current number of rows in the loop.
<c:foreach var= "" items= "" varstatus= "status" > <c:if test= "${status.index% 4 = 0}" > <br/> <!--is a table Just add a <tr></tr>-</c:if></c:forEach>
Struts foreach wraps each of the 4 elements, how to implement
<c:foreach var= "Item" item= "${list}" varstatus= "status" >
<!--output--
${item},
<!--wrap every 4 elements one time--
<c:if test= "${status.count% 4 = = 0}" >
<br/>
</c:if>
</c:foreach>
Use C:foreach to control 5 line breaks, ForEach wrap