Latest web development tutorials

<X: forEach> tag

Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag

<X: forEach> tag viene utilizzato per scorrere i nodi di un documento XML.

sintassi

<x:forEach
   var="<string>"
   select="<string>"
   begin="<int>"
   end="<int>"
   step="<int>"
   varStatus="<string>">

proprietà

<X: forEach> tag ha i seguenti attributi:

proprietà descrizione Se necessario difetto
selezionare espressione XPath da calcolare è no
var Variabile viene utilizzata per memorizzare il progetto attuale no no
iniziare Inizia indice iteratore no no
fine Indice di fine iteratore no no
passo passo iterazione no no
varStatus Stato delle variabili memorizzate per conto di iteratore no no


Esempi 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>

I risultati sono i seguenti:

BOOKS INFO:
Book Name: Padam History

Book Name: Great Mistry

Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag