Jstl details 3

Source: Internet
Author: User
9.3.2 <C: Set> label used for value assignment
<C: Set> A tag is used to assign values to variable attributes in a variable or JavaBean. Its Attributes and descriptions are shown in table 9.4:
Table 9.4 <C: Set> label attributes and descriptions
Attribute description
Value information, which can be an El expression or constant
The name of the JavaBean instance to which target is assigned. If this attribute exists, the property attribute must exist (optional)
Property JavaBean instance variable property name (optional)
Variable name assigned to VaR (optional)
Scope variable. If not specified, the default value is page (optional)

If the attribute of value does not exist, the object data contained in the tag is used as the value assignment content. The following is an example:
<C: Set Value = "this is Andy" Var = "onestring"/>
$ {Onestring} <br>
In this example, the variable named "onestring" is assigned "this is Andy", and its scope is page.
9.3.3 <C: Remove> label used for deletion
<C: Remove> the label is used to delete variables that exist in the scope. Its Attributes and descriptions are shown in table 9.5:
Table 9.5 <C: Remove> label attributes and descriptions
Attribute description
Name of the variable to be deleted by VAR
Scope variable scope. If not specified, all search is performed by default (optional)

The following is an example:
<C: Remove Var = "samplevalue" Scope = "session"/>
$ {Sessionscope. samplevalue} <br>
This example deletes the variable "samplevalue" in the session. When the next El expression shows the variable, the variable does not exist.
9.3.4 <C: Catch> label used for exception capture
<C: Catch> tags allow exceptions to be caught on JSP pages. It contains a var attribute, which is a variable that describes exceptions. The change quantity is optional. If the VaR attribute is not defined, only exceptions are caught and nothing is done. If the VaR attribute is defined, you can use the exception variable defined by VAR to determine whether to forward data to other pages or prompt an error message. Let's look at an example.
<C: Catch Var = "Err">
$ {Param. samplesinglevalue [9] = 3}
</C: Catch>
$ {Err}
When "$ {Param. if an exception exists in the samplesinglevalue [9] = 3} "expression, you can obtain the exception from the VaR attribute" Err, the error message is usually determined by determining whether "Err" is null.
9.3.5 <C: If> tag used for judgment
<C: If> labels are used in simple condition statements. Its Attributes and descriptions are shown in Table 9.6:
Table 9.6 <C: If> label attributes and descriptions
Attribute description
Conditions to be determined by test
VaR stores the variable name that determines whether the result is true or false. This variable is available for later work (optional)
Scope variable scope. If not specified, the default value is the variable stored in the page range (optional)

The following is an example:
<C: If test = "$ {paramvalues. samplevalue [2] = 12}" Var = "visits">
It is 12
</C: If> <br>
$ {Visits} <br>
This example checks whether the content of the control with the subscript of "2" is "12" in the input control array parameters submitted by the request. If it is 12, "It is 12" is displayed ". The judgment result is saved in the "visits" variable in the page range.
9.3.6 <C: Choose>, <C: When>, and <C: otherwise> labels used for complex judgment
These three labels are used to implement complex condition judgment statements, similar to the condition statements of "if, elseif.
Q <C: Choose> A tag has no attributes and can be considered as a parent tag. <C: When> and <C: otherwise> are used as their subtags.
The q <C: When> label is equivalent to the "if" statement. It contains a test attribute, which indicates the condition to be judged.
Q <C: otherwise> A tag has no attribute. It is equivalent to an "else" statement.
The following is an example of a complex condition statement.
<C: Choose>
<C: When test = "$ {paramvalues. samplevalue [2] = 11}">
Not 12 not 13, it is 11
</C: When>
<C: When test = "$ {paramvalues. samplevalue [2] = 12}">
Not 11 not 13, it is 12
</C: When>
<C: When test = "$ {paramvalues. samplevalue [2] = 13}">
Not 11 not 12, it is 13
</C: When>
<C: otherwise>
Not 11, 12, 13
</C: otherwise>
</C: Choose>
This example checks whether the content of the subscript "2" control is "11", "12", or "13" in the input control array parameters submitted by the request ", the statement is displayed based on the judgment result. If none of the statements are displayed, "not 11, 12, 13" is displayed ".
9.3.7 <C: foreach> label used for Loop
<C: foreach> is a loop control label. Its Attributes and descriptions are shown in Table 9.7:
Table 9.7 <C: foreach> label attributes and descriptions
Attribute description
(Optional) set of cycles for items)
Begin start condition (optional)
End end condition (optional)
Step of a step loop. The default value is 1 (optional)
Variable name of the object in which var loops are made. If the items attribute exists, it indicates the variable name of the object in the Loop set (optional)
Variable for varstatus to show loop status (optional)

The following is an example of a set loop.
<% Arraylist = new arraylist ();
Arraylist. Add ("AA ");
Arraylist. Add ("BB ");
Arraylist. Add ("cc ");
%>
<% Request. getsession (). setattribute ("arraylist", arraylist); %>
<C: foreach items = "$ {sessionscope. arraylist}" Var = "arraylisti">
$ {Arraylisti}
</C: foreach>
In this example, the objects in the arraylist type set parameters saved in the session are read in sequence. The items attribute points to the arraylist type set parameters, the VaR attribute defines a new variable to receive objects in the set. Finally, the El expression is directly displayed on the page. The following is an example of a simple loop.
<C: foreach Var = "I" begin = "1" End = "10" step = "1">
$ {I} <br/>
</C: foreach>
This example loops from "1" to "10" and displays the variable "I" in the loop on the page.
9.3.8 <C: fortokens> label used to separate characters
<C: fortokens> A tag can be used to separate a specified string based on a separator, which is equivalent to the java. util. stringtokenizer class. Its Attributes and descriptions are shown in Table 9.8:
Table 9.8 <C: fortokens> label attributes and descriptions
Attribute description
El expressions or constants separated by items
Delims Separator
Begin start condition (optional)
End end condition (optional)
Step of a step loop. The default value is 1 (optional)
(Optional) Name of the variable of the object that VaR performs a loop)
Variable for varstatus to show loop status (optional)

The following is an example.
<C: fortokens items = "AA, BB, CC, DD" begin = "0" End = "2" step = "2" delims = ", "Var =" avalue ">
$ {Avalue}
</C: fortokens>
The string to be separated is "AA, BB, CC, DD", and the separator is ",". The begin attribute is specified to start from the first ",", and the end attribute is specified to be separated to the third ",", and the variable name used for loop is specified as "avalue ". Because the step size is "2", only "AA cc" can be displayed in the El expression $ {avalue"

 

9.3.2 <C: Set> label used for value assignment
<C: Set> A tag is used to assign values to variable attributes in a variable or JavaBean. Its Attributes and descriptions are shown in table 9.4:
Table 9.4 <C: Set> label attributes and descriptions
Attribute description
Value information, which can be an El expression or constant
The name of the JavaBean instance to which target is assigned. If this attribute exists, the property attribute must exist (optional)
Property JavaBean instance variable property name (optional)
Variable name assigned to VaR (optional)
Scope variable. If not specified, the default value is page (optional)

If the attribute of value does not exist, the object data contained in the tag is used as the value assignment content. The following is an example:
<C: Set Value = "this is Andy" Var = "onestring"/>
$ {Onestring} <br>
In this example, the variable named "onestring" is assigned "this is Andy", and its scope is page.
9.3.3 <C: Remove> label used for deletion
<C: Remove> the label is used to delete variables that exist in the scope. Its Attributes and descriptions are shown in table 9.5:
Table 9.5 <C: Remove> label attributes and descriptions
Attribute description
Name of the variable to be deleted by VAR
Scope variable scope. If not specified, all search is performed by default (optional)

The following is an example:
<C: Remove Var = "samplevalue" Scope = "session"/>
$ {Sessionscope. samplevalue} <br>
This example deletes the variable "samplevalue" in the session. When the next El expression shows the variable, the variable does not exist.
9.3.4 <C: Catch> label used for exception capture
<C: Catch> tags allow exceptions to be caught on JSP pages. It contains a var attribute, which is a variable that describes exceptions. The change quantity is optional. If the VaR attribute is not defined, only exceptions are caught and nothing is done. If the VaR attribute is defined, you can use the exception variable defined by VAR to determine whether to forward data to other pages or prompt an error message. Let's look at an example.
<C: Catch Var = "Err">
$ {Param. samplesinglevalue [9] = 3}
</C: Catch>
$ {Err}
When "$ {Param. if an exception exists in the samplesinglevalue [9] = 3} "expression, you can obtain the exception from the VaR attribute" Err, the error message is usually determined by determining whether "Err" is null.
9.3.5 <C: If> tag used for judgment
<C: If> labels are used in simple condition statements. Its Attributes and descriptions are shown in Table 9.6:
Table 9.6 <C: If> label attributes and descriptions
Attribute description
Conditions to be determined by test
VaR stores the variable name that determines whether the result is true or false. This variable is available for later work (optional)
Scope variable scope. If not specified, the default value is the variable stored in the page range (optional)

The following is an example:
<C: If test = "$ {paramvalues. samplevalue [2] = 12}" Var = "visits">
It is 12
</C: If> <br>
$ {Visits} <br>
This example checks whether the content of the control with the subscript of "2" is "12" in the input control array parameters submitted by the request. If it is 12, "It is 12" is displayed ". The judgment result is saved in the "visits" variable in the page range.
9.3.6 <C: Choose>, <C: When>, and <C: otherwise> labels used for complex judgment
These three labels are used to implement complex condition judgment statements, similar to the condition statements of "if, elseif.
Q <C: Choose> A tag has no attributes and can be considered as a parent tag. <C: When> and <C: otherwise> are used as their subtags.
The q <C: When> label is equivalent to the "if" statement. It contains a test attribute, which indicates the condition to be judged.
Q <C: otherwise> A tag has no attribute. It is equivalent to an "else" statement.
The following is an example of a complex condition statement.
<C: Choose>
<C: When test = "$ {paramvalues. samplevalue [2] = 11}">
Not 12 not 13, it is 11
</C: When>
<C: When test = "$ {paramvalues. samplevalue [2] = 12}">
Not 11 not 13, it is 12
</C: When>
<C: When test = "$ {paramvalues. samplevalue [2] = 13}">
Not 11 not 12, it is 13
</C: When>
<C: otherwise>
Not 11, 12, 13
</C: otherwise>
</C: Choose>
This example checks whether the content of the subscript "2" control is "11", "12", or "13" in the input control array parameters submitted by the request ", the statement is displayed based on the judgment result. If none of the statements are displayed, "not 11, 12, 13" is displayed ".
9.3.7 <C: foreach> label used for Loop
<C: foreach> is a loop control label. Its Attributes and descriptions are shown in Table 9.7:
Table 9.7 <C: foreach> label attributes and descriptions
Attribute description
(Optional) set of cycles for items)
Begin start condition (optional)
End end condition (optional)
Step of a step loop. The default value is 1 (optional)
Variable name of the object in which var loops are made. If the items attribute exists, it indicates the variable name of the object in the Loop set (optional)
Variable for varstatus to show loop status (optional)

The following is an example of a set loop.
<% Arraylist = new arraylist ();
Arraylist. Add ("AA ");
Arraylist. Add ("BB ");
Arraylist. Add ("cc ");
%>
<% Request. getsession (). setattribute ("arraylist", arraylist); %>
<C: foreach items = "$ {sessionscope. arraylist}" Var = "arraylisti">
$ {Arraylisti}
</C: foreach>
In this example, the objects in the arraylist type set parameters saved in the session are read in sequence. The items attribute points to the arraylist type set parameters, the VaR attribute defines a new variable to receive objects in the set. Finally, the El expression is directly displayed on the page. The following is an example of a simple loop.
<C: foreach Var = "I" begin = "1" End = "10" step = "1">
$ {I} <br/>
</C: foreach>
This example loops from "1" to "10" and displays the variable "I" in the loop on the page.
9.3.8 <C: fortokens> label used to separate characters
<C: fortokens> A tag can be used to separate a specified string based on a separator, which is equivalent to the java. util. stringtokenizer class. Its Attributes and descriptions are shown in Table 9.8:
Table 9.8 <C: fortokens> label attributes and descriptions
Attribute description
El expressions or constants separated by items
Delims Separator
Begin start condition (optional)
End end condition (optional)
Step of a step loop. The default value is 1 (optional)
(Optional) Name of the variable of the object that VaR performs a loop)
Variable for varstatus to show loop status (optional)

The following is an example.
<C: fortokens items = "AA, BB, CC, DD" begin = "0" End = "2" step = "2" delims = ", "Var =" avalue ">
$ {Avalue}
</C: fortokens>
The string to be separated is "AA, BB, CC, DD", and the separator is ",". The begin attribute is specified to start from the first ",", and the end attribute is specified to be separated to the third ",", and the variable name used for loop is specified as "avalue ". Because the step size is "2", only "AA cc" can be displayed in the El expression $ {avalue"

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.