📄 x_foreach.jsp
字号:
<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<html>
<head><title>JSTL: XML -- forEach</title></head>
<body>
<h3>forEach实例</h3>
<x:parse var="xmlText">
<books>
<book>
<name>JSP2.0</name>
<publisher>清华出版社</publisher>
<price>48</price>
<authors>
<author id="1">
<name>Johnson</name>
<address>Johnson@hotmail.com</address>
</author>
<author id="2">
<name>Tom</name>
<address>Tom@hotmail.com</address>
</author>
</authors>
</book>
</books>
</x:parse>
<x:forEach select="$xmlText/books">
<x:out select="."/><br>
</x:forEach>
<x:forEach select="$xmlText//book">
<x:if select=".//author">
<x:out select=".//author/name" />
</x:if><br>
</x:forEach>
<x:forEach select="$xmlText//book">
<x:choose>
<x:when select='$xmlText//author[@id="2"]'>
<x:out select='$xmlText//author[@id="2"]'/>
</x:when>
<x:otherwise>
no author's id=2
</x:otherwise>
</x:choose>
</x:forEach>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -