I. Core tag libraries mainly include general tags, condition tags, iteration tags, and URL-related tags.
Add the code at the beginning of the JSP file using the core tag Library:
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "C" %>
II. General Purpose labels, such as <C: Out>, <C: Set>, <C: Remove>, and <C: Catch>
1. The <C: Out> label is used for output.
Output the computing result to the jspwriter object.
Syntax 1: no body.
<C: Out value = "value" [escapexml = "{true | false}"] [default = "defaultvalue"]/>
Syntax 2: body.
<C: Out value = "value" [escapexml = "{true | false}"]>
Defaultvalue <! --- It can be JSP code->
</C: Out>
Attribute:
Value: object, the expression to be calculated ).
Excapexml: Boolean, determines whether the following characters are converted into character entity code in the result string. The default value is true.
Character |
Character entity |
< |
& Lt; |
> |
& Gt; |
& |
& Amp; |
' " |
& #039; & #034; |
Default: object. If the value is null, the default value is output.
2. The <C: Set> label is used to assign values.
This label is used to set a value in a certain range (request, session, application, etc.) or set the attributes of an object.
Syntax 1: Use the value attribute to set attributes in a specific range.
<C: Set Value = "value" Var = "varname" [scope = "{page | request | session | application}"]/>
Syntax 2: Use the value attribute to set an attribute in a specific range with a body.
<C: Set Var = "varname" [scope = "{page | request | session | application}"]>
Body content
</C: Set>
Syntax 3: Set an attribute of a specific object.
<C: Set Value = "value" target = "target" property = "propertyname"/>
Syntax 4: Set an attribute of a specific object and the tag has a body.
<C: set target = "target" property = "propertyname">
Body content
</C: Set>
Attribute:
Value: object, the expression to be calculated
VaR: String, used to indicate the attribute of the value.
Scope: Valid range of string and VaR
Target: string, the object to be set. It must be a JavaBeans or Java. util. map object.
Property: object, the name of the property in the target object to be set
3. <C: Remove> This label is used to delete a variable or attribute.
Syntax:
<C: Remove Var = "varname" [scope = "{page | request | session | application}"]/>
Attribute:
Scope: string, the range of this parameter.
VaR: string, the name of the parameter to be deleted
4. <C: Catch> capture exceptions thrown by labels nested in it.
Syntax:
<C: catch [Var = "varname"]>
Nestedactions
</C: Catch>
Attribute:
VaR: String, used to indicate the name of the exception
3. Condition tags
In jstl, condition labels are;
<C: If>
<C: Choose>
<C: When>
<C: otherwise>
The following sections describe each other.
1. <C: If> is used for condition determination. If its test attribute is true, its body is calculated.
Syntax 1: no body.
<C: If test = "testcondition" Var = "varname" [scope = {page | request | session | application}]/>
Syntax 2: bosy.
<C: If
Test = "testcondition"
[Var = "varname"]
[Scope = {page | request | session | application}]>
Body content
</C: If>
Attribute:
Test: Boolean, a condition of the expression
VaR: string, the value calculated by the test condition expression. Its type is boolean.
Scope: range of string and VaR
2,<C: Choose>Used for condition selection. It is used with <C: When> and <C: otherwise>.
Syntax:
<C: Choose>
Body content (<when> and <otherwise> subtags)
</Choose>
Note: its body content can only consist of the following elements:
Space.
0 or more <when> sub-labels, <when> must appear before <otherwise> labels.
0 or more <otherwise> sub-labels.
3,
<C: When>
It represents a condition branch of <C: Choose>.
Syntax:
<C: When test = "testcondition">
Body content
</C: When>
Attribute:
Test: Boolean, a condition of the expression
It has two restrictions:
<C: Choose> must be used as its parent label.
Must appear before <C: othewise>.
4,<C: otherwise>It represents the final choice of <C: Choose>.
Syntax:
<C: otherwise>
Conditional Block
</C: otherwise>
There are two restrictions on its use.
<C: Choose> must be used as its parent label.
It must be the last branch of <C: Choose>.
IV,Iteration tag
In jstl, iteration labels include:
<C: foreach>
<C: fortokens>
1. <C: foreach>
-A tag is used to iterate over a set containing multiple objects, repeat its TAG body, or repeat a fixed number of iterations.
Iterates the bodycontent of an object in a collection, or repeats the iteration for a fixed number of times.
Syntax 1: iteration in collection.
<C: foreach
[Var = "varname"]
Items = "collection"
[Varstatus = "varstatusname"]
[Begin = "begin"]
[END = "end"] [step = "step"]>
Body content
</C: foreach>
Syntax 2: Fixed iterations.
<C: foreach
[Var = "varname"]
[Varstatus = "varstatusname"]
Begin = "begin"
End = "end"
[Step = "step"]>
Body content
</C: foreach>
Attribute:
VaR: string, the name of the iteration parameter.
Items: the set of items to be iterated for any supported types.
Varstatus: String, indicating the iteration status. You can access the iteration information.
Begin: Int. If items is specified, iteration starts from index [begin] of items. If items is not specified, iteration starts from the specified index, it is equivalent to the for (INT I = begin;) statement.
End: Int. If items is specified, the iteration ends at the index [end] of items. If items is not specified, the iteration ends at the specified index, which is equivalent to (; I <end ;).
Step: int, the iteration step.
2. <C: fortokens> label
-<C: fortokens> A tag is used to browse all members of a string. Its members are separated by delimiters.
<C: fortokensitems = "A: B: C: D" delims = ":" Var = "token">
<C: Out value = "$ {token}"/> <br>
</C: fortokens>