Use c: forEach to control 5 line breaks and foreach line breaks

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.