Use c: forEach to control 5 line breaks and foreach line breaks
When I was working on a project today, I encountered a problem. I needed to display images of uncertain numbers on the webpage (the images were retrieved from the database). I used the <c: forEach> cyclic value. You need to create a row to display a fixed number of images. The Code is as follows (here I control five 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 indicates the number of iterations of the current iteration starting from 1.
A: <c: forEach> traverses the array content. jsp displays a line feed for every four
<C: forEach> there is also a varStatus attribute. VarStatus. index is used to obtain the current number of rows in the traversal.
<C: forEach var = "" items = "" varStatus = "status"> <c: if test = "$ {status. index % 4 = 0} "> <br/> <! -- Add a <tr> </tr> --> </c: if> </c: forEach> to the table.
How can struts foreach wrap every four elements?
<C: foreach var = "item" item = "$ {list}" varStatus = "status">
<! -- Output -->
$ {Item },
<! -- Line feed every four elements -->
<C: if test = "$ {status. count % 4 = 0}">
<Br/>
</C: if>
</C: foreach>