<X: forEach> -Tag
JSP Standard - Tag - Bibliothek
<X: forEach> -Tag wird in einer Schleife durch die Knoten eines XML-Dokuments verwendet.
Syntax
<x:forEach var="<string>" select="<string>" begin="<int>" end="<int>" step="<int>" varStatus="<string>">
Immobilien
<X: forEach> Tag hat folgende Attribute:
Immobilien | Beschreibung | notfalls | Default |
---|---|---|---|
wählen | XPath-Ausdruck berechnet werden | es ist | keine |
var | Variable wird verwendet, um das aktuelle Projekt zu speichern | keine | keine |
beginnen | Startindex Iterator | keine | keine |
Ende | End Index Iterator | keine | keine |
Schritt | Iterationsschritt | keine | keine |
varStatus | Der Status von Variablen im Auftrag von Iterator gespeichert | keine | keine |
Beispiele Demo
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <html> <head> <title>JSTL x:forEach 标签</title> </head> <body> <h3>Books Info:</h3> <c:set var="xmltext"> <books> <book> <name>Padam History</name> <author>ZARA</author> <price>100</price> </book> <book> <name>Great Mistry</name> <author>NUHA</author> <price>2000</price> </book> </books> </c:set> <x:parse xml="${xmltext}" var="output"/> <ul class="list"> <x:forEach select="$output/books/book/name" var="item"> <li>Book Name: <x:out select="$item" /></li> </x:forEach> </ul> </body> </html>
Ergebnisse sind wie folgt:
BOOKS INFO: Book Name: Padam History Book Name: Great Mistry
JSP Standard - Tag - Bibliothek