<C: forEach>, <C: forTokens> tag
Queste etichette sono incapsulati in Java for, while, do-while.
Al contrario, <c: forEach> tag è un'etichetta più generica, perché è un insieme di oggetti iterazione.
<C: forTokens> tag specificando una stringa delimitatore separata in un array poi iterare.
sintassi forEach
<c:forEach items="<object>" begin="<int>" end="<int>" step="<int>" var="<string>" varStatus="<string>"> ...
sintassi forTokens
<c:forTokens items="<string>" delims="<string>" begin="<int>" end="<int>" step="<int>" var="<string>" varStatus="<string>">
proprietà
<C: forEach> tag ha i seguenti attributi:
proprietà | descrizione | Se necessario | difetto |
---|---|---|---|
articoli | Informazioni da circolare | no | no |
iniziare | inizio Element (0 = primo elemento, il secondo elemento = 1) | no | 0 |
fine | L'ultimo elemento (0 = primo elemento, il secondo elemento = 1) | no | Ultimo elemento |
passo | Ogni iterazione passo | no | 1 |
var | Nome della variabile rappresenta la voce corrente | no | no |
varStatus | Rappresentante stato circolazione nome della variabile | no | no |
<C: forTokens> e <c: forEach> tag ha proprietà simili, ma <C: forTokens> ha un altro attributo:
proprietà | descrizione | Se necessario | difetto |
---|---|---|---|
delims | separatore | è | no |
<C: forEach> istanza demo
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:forEach 标签实例</title> </head> <body> <c:forEach var="i" begin="1" end="5"> Item <c:out value="${i}"/><p> </c:forEach> </body> </html>
I risultati sono i seguenti:
Item 1 Item 2 Item 3 Item 4 Item 5
<c: forTokens> Esempi Demo
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:forTokens 标签实例</title> </head> <body> <c:forTokens items="google,w3big,taobao" delims="," var="name"> <c:out value="${name}"/><p> </c:forTokens> </body> </html>
I risultati sono i seguenti:
google w3big taobao