Jstl label: C: foreach

Source: Internet
Author: User

 

For Loop Control, it can browse the members in the collection in sequence. The operating method is to repeatedly execute the body content when the conditions are met. For Loop Control, it can browse the members in the collection in sequence. The operating method is to repeatedly execute the body content when the conditions are met. Syntax 1: iterate all the members of a set object<C: foreach [Var = "varname"] items = "Collection" [varstatus = "varstatusname"] [begin = "begin"] [END = "end"] [step = "step" ]> body content </C: foreach>Syntax 2: number of iterations<C: foreach [Var = "varname"] [varstatus = "varstatusname"] Begin = "begin" End = "end" [step = "Step"]> body content </C: foreach>A tag has the following attributes: var: the name of the iteration parameter. The name of the variable that can be used in the iteration body to represent each iteration variable. The type is string. Items: the set to be iterated. The supported types are described below. Varstatus: the name of the iteration variable. It is used to indicate the iteration status and can access the information of the iteration itself. Begin: If items is specified, iteration starts from items [begin]. If items is not specified, iteration starts from begin. Its type is an integer. End: If items is specified, the iteration ends at items [end]. If items is not specified, the iteration ends at end. Its type is also an integer. Step: the iteration step. The items attribute of tags supports all standard set types provided by the Java platform. In addition, you can use this operation to iterate elements in an array (including an array of basic types. The supported collection types and iterative elements are as follows: Java. util. Collection: Elements obtained by calling iterator. Java. util. MAP: the Instance obtained through java. util. Map. Entry. Java. util. iterator: iterator element. Java. util. enumeration: enumeration element. Object instance array: array element. Basic Type value array: Elements of the encapsulated array. String to be separated by commas (,): The Sub-string after segmentation. Javax. servlet. jsp. jstl. SQL. Result: The row obtained by the SQL query. Whether it is an integer or an iteration of a set, the varstatus attribute plays the same role. Like the VaR attribute, varstatus is used to create a variable with a limited scope (the change volume only works in the current TAG body ). However, the variable named by the varstatus attribute does not store the current index value or the current element, but is assigned to an instance of the javax. servlet. jsp. jstl. Core. looptagstatus class. This class contains a series of features that describe the current state of the iteration. The meanings of these attributes are as follows: Current: The items of the current iteration (in the set. Index: The index of the current iteration that starts from 0. Count: the number of iterations of the current iteration starting from 1. First: indicates whether the current iteration is the first iteration. This attribute is of the boolean type. Last: indicates whether the current iteration is the last iteration. This attribute is of the boolean type. Begin: the value of the begin attribute. The value of the end: End attribute step: the value of the Step attribute. Here are some basic examples. The background color of the table is changed.<C: foreach Var = "item" items = "$ {contents}" varstatus = "status"> <tr> <C: If test = "$ {status. count % 2 = 0} "> bgcolor =" # ccccfe "</C: If> align =" Left "> XXX </tr> </C: foreach>Restrictions: If the begin attribute exists, the begin attribute must be greater than or equal to 0. If the end attribute exists, it must be greater than begin. If the step attribute exists, step must be greater than or equal to 0 null and error handling. If items is null, it is an empty set object. If begin is greater than or equal to items, the iteration does not indicate that if you want to browse a collection object in sequence and display its content, you must have the items attribute. In the example below, core_foreach.jsp displays the members in the array one by one:

  • Previous Article: getting started with extjs, I feel a little disappointed.
  • Next article: Use Asp.net (C #) to batch upload images and automatically generate thumbnails, text watermarks, and image watermarks
  • Related Article

    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.