Process Control <C: If> <C: Choose> <C: When> <C: otherwise>
Bytes --------------------------------------------------------------------------------------
<C: If test (the test attribute must be available) = "test condition" Var = "used to store the result after test">
When the condition is true, the execution body content
</C: If>
<C: If test = "{Param. Username} = 'admin'" Var = "con">
Hello, admin
</C: If>
$ {Con}
During execution, add? Username = Admin
-------------------------------------------
<C: Choose> is used only as the parent label of <C: When> and <C: otherwise>.
<C: Choose> </C: Choose> the subject content is
1. Blank
<C: When> 2.1 or more
3.0 or 1 <C: otherwise>, <C: When> must be before <C: otherwise>
<C: When test = "Required Test Conditions">
-------------------------------------------
Example 1: Use JSF as follows:
<C: foreach items = "# {usersubsyscentaction. cents}" Var = "cents">
<DT> available points: </DT>
<DD>
<H: outputtext value = "# {cents [0]}"> <DD>
<DT> accumulated points: </DT>
<DD>
<H: outputtext value = "# {cents [1]}"> <DD>
<DT> user level: </DT>
<DD>
<C: Choose>
<C: When test = "$ {cents [1] <1000}">
<Span> initial & nbsp </span> level
</C: When>
<C: otherwise>
<H: outputtext value = "# {(cents [1]-cents [1] % 1000)/1000}"> <F: convertnumber type = "currency" maxfractiondigits = "0" minfractiondigits = "0" pattern = "###, ###, ###"/> </C: otherwise>
</C: Choose>
</DD>
</C: foreach>
Example 2: use JSP as follows:
<C: foreach items = "$ {pagelist}" Var = "orgfeepersoninfovo" varstatus = "S">
<Tr align = "center" class = "tablebgl" id = "modified">
<TD> <C: Out value = "$ {S. index + 1}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. plantaskid}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. assessstartdate}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. assessenddate}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. acceptorg}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. assesstasktype}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. cnaslinkman}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. ischief} "/> <C: Out value =" $ {orgfeepersoninfovo. persontype} "/> <C: Out value =" $ {orgfeepersoninfovo. stationstr} "/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. assesssumday}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. addsumday}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. rewritemanname}"/> </TD>
<TD> <C: Out value = "$ {orgfeepersoninfovo. rewritedatetime}"/> </TD>
</Tr>
</C: foreach>
Bytes --------------------------------------------------------------------------------------------
To put it simply, the <C: foreach> label is used to iteratively output the content inside the tag. It can be a fixed number of iterations, or the number of iterations can be determined based on the number of objects in the set.
<C: foreach> the syntax of a tag is defined as follows.
<C: foreach Var = "name" items = "expression" varstatus = "name"
Begin = "expression" End = "expression" step = "expression">
Body content
</C: foreach>
<C: foreach> A tag has the following attributes:
The name of the VaR iteration parameter. The name of the variable that can be used in the iteration body, used to store the currently specified member; string
Varstatus is used to store information about the members of the specified member. String
Whether it is an integer or an iteration of a set, the varstatus attribute of <C: foreach> 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 iteration. The meanings of these attributes are as follows:
L current: the items in the current iteration (in the set.
L index: the index of the current iteration that starts from 0.
L count: the number of iterations of the current iteration starting from 1.
L first: indicates whether the current iteration is the first iteration. This attribute is of the boolean type.
L last: indicates whether the current iteration is the last iteration. This attribute is of the boolean type.
L begin: the value of the begin attribute.
L end: End Attribute Value
L step: the value of the Step attribute
The set of items to be iterated, including: arrays collection iterator enumeration map string
L java. util. Collection: Elements obtained by calling iterator.
L java. util. MAP: the Instance obtained through java. util. Map. Entry.
L java. util. iterator: iterator element.
L java. util. enumeration: enumeration element.
L object instance array: array element.
L basic type value array: packaged array elements.
L string to be bounded by commas (,): The Sub-string after segmentation.
L javax. servlet. jsp. jstl. SQL. Result: The row obtained by the SQL query.
If itin specifies items, the iteration starts from items [begin]. If items is not specified, the iteration starts from begin. Its type is an integer.
If items is specified for end, the iteration ends at items [end]. If items is not specified, the iteration ends at end. Its type is also an integer.
Step of step iteration. Int
Limit begin. If a value must be greater than 0, end must be greater than begin.
Step must be greater than or equal to 1
<%
String a [] = new string [3];
A [0] = "hello ";
A [1] = "this ";
A [2] = "is a test ";
Request. setattribute ("ATT", );
%>
<C: foreach items = "$ {" ATT "}" Var = "items" varstatus = "S">
$ {Item}
The effective range of item is in foreach.
Index: $ {S. Index}
Count: $ {S. Count}
First: $ {S. First}
Last: $ {S. Last}
</C: foreach>
The output of different begin and end settings is different.
The following are two basic examples. The first example is to output elements in the Set in sequence.
<C: foreach Var = "item" items = "$ {contents}" varstatus = "status">
$ Status. Count: $ {item}
</C: foreach>
The following example is a fixed number of iterations, which is used to output a square value ranging from 1 to 9.
<C: foreach Var = "X" begin = "1" End = "9" step = "1">
$ {X * x}
</C: foreach>
-------------------------------------------
<C: fortokens>
</C: fortokens> is used to browse all the members of a string. Its member definitions are separated by definition symbols.
Delims defines characters used to separate strings
<C: foreach> You can also separate strings, but cannot set separators.
<C: foreach items = "a, B, c, d" Var = "item">
$ {Item}
</C: foreach>
<C: fortoken items = "a, B, c, d" Var = "item" delims = ",">
$ {Item}
</C: foreach>
<C: fortoken items = "123-456-789" Var = "item" delims = "-">
$ {Item}
</C: foreach>
-------------------------------------------