Professional Documents
Culture Documents
JSTL
JSTL
xmlns:c="http://java.sun.com/jstl/core"
version="1.2">
It provides the following basic scripting functions:
<c:out value="..."/>
<c:set var="..." value="..."/>
<c:if test="...">body</c:if>
<c:choose>body</c:choose>
<c:forEach items="...">body</c:forEach>
<c:forTokens items="..."
delims="...">body</c:forTokens>
c:out Action
<c:out
value="text_mixed_with_expressions"/>
The "value" attribute will be evaluated and the resulting
value will be converted into a string which will be inserted
into the HTTP response. The c:out action serves similar
purposes as the JSP expression element.
c:set Action
<c:set var="name" value="expression"/>
The "var" attribute specifies a variable name, which will be
declared and assigned with the value resulted from the
"value" attribute. The c:set action serves similar purposes as
the Java assignment statement.
c:if Action
<c:if test="expression"/>
body
</c:if>
If the "test" attribute is evaluated to true, body will be
processed. The c:if action serves similar purposes as the
Java if statement.
c:choose Action
<c:choose>
<c:when test="expression">
body
</c:when>
<c:when test="expression">
body
</c:when>
...
<c:otherwise>
body
</c:otherwise>
</c:choose>
The body of the first c:when action that has the "test"
attribute evaluated to true will be processed. If all "test"
attributes are evaluated to false, the body of the c:otherwise
action will be processed. The c:choose action serves similar
purposes as the Java if-else statement.
c:forEach Action
<c:forEach var="name" items="expression"
begin="expression" end="expression"
step="expression">
body
</c:forEach>
If the "items" attribute is specified, it will be used to
identify an array or collection object, the elements in the
array or collection will be iterated. At each iteration, the
current element will assign to a named variable specified in
the "var" attribute, and body will be processed. If the
"begin", "end" or "step" attribute is specified, it will be used
to restrict the beginning element, the ending element, or the
step size of the iteration.
If the "items" attribute is not specified, an index integer will
be used to iterate from the "begin" value to the "end" value
stepping with the "step" value.
The c:forEach action serves similar purposes as the Java for
statement. But there is no break mechanism.
c:forTokens Action
<c:forTokens var="name"
items="expression" delims="expression"
begin="expression" end="expression"
step="expression">
body
</c:forTokens>
The string specified by the "items" attribute will be
tokenized with the delimiter specified by the "delims"
attribute. Then resulting tokens will be iterated. At each
iteration, the current token will assign to a named variable
specified in the "var" attribute, and body will be processed.
If the "begin", "end" or "step" attribute is specified, it will
be used to restrict the beginning element, the ending
element, or the step size of the iteration.