jstl 标签,实例代码和用法。
存在这些标签嵌入Java的一个很好的选择,让while或do-while循环通过脚本。<c:forEach>标记是常用的标签,因为它遍历对象的集合。<c:forTokens>标签是用来打破的字符串令牌和遍历每个标记。
属性:
<c:forEach>标记有以下属性:
| 属性 | 描述 | 必需 | Default |
|---|---|---|---|
| items | Information to loop over | No | None |
| begin | Element to start with (0 = first item, 1 = second item, ...) | No | 0 |
| end | Element to end with (0 = first item, 1 = second item, ...) | No | Last element |
| step | Process every step items | No | 1 |
| var | Name of the variable to expose the current item | No | None |
| varStatus | Name of the variable to expose the loop status | No | None |
<c:forTokens>标签有类似<c:forEach>的属性,除了一个额外的属性delims指定要使用的字符作为分隔符。
| 属性 | 描述 | Required | Default |
|---|---|---|---|
| delims | Characters to use as delimiters | Yes | None |
<c:forEach>例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forEach> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:forEach var="i" begin="1" end="5">
Item <c:out value="${i}"/><p>
</c:forEach>
</body>
</html>
这将产生以下结果:
Item 1 Item 2 Item 3 Item 4 Item 5
<c:forTokens>例子:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forTokens> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:forTokens items="Zara,nuha,roshy" delims="," var="name">
<c:out value="${name}"/><p>
</c:forTokens>
</body>
</html>
这将产生以下结果:
Zara nuha roshy
本文介绍JSTL中的<c:forEach>和<c:forTokens>标签的使用方法,包括属性说明及示例代码。这两个标签常用于在JSP页面中进行循环操作。

被折叠的 条评论
为什么被折叠?



