x_flowcontrol.jsp

来自「《精通JSP编程 》源代码(赵强那本) 很有用的源代码」· JSP 代码 · 共 67 行

JSP
67
字号
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ page contentType="text/html; charset=gb2312" language="java" %>

<html>
<head>
  <title>JSTL: XML Support --综合实例</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Parse / ForEach</h3>

<x:parse var="document">
  <GetAllBooks>
           <book id="1234">
				<name>JSP2.0</name>
				<publisher>电子工业出版社</publisher>
				<price>xxx</price>
				<category>计算机</category>
				<description>JSP开发最新的书</description>
				<authors>
		           <author id="1">
		              <name>john</name>
		              <address>address:xxxx1</address>
		            </author>
		            <author id="2">
		              <name>alice</name>
		              <address>address:xxxx2</address>
		            </author>
		        </authors>
           </book>
     </GetAllBooks>        
</x:parse>

<x:forEach select="$document/GetAllBooks">
  -> <x:out select="."/>
  <br>
</x:forEach>

<hr/>

<x:forEach select="$document//book">
  -> 
  <x:if select=".//author">
   <x:out select=".//author/name"/>
  </x:if>
  <br/>
</x:forEach>
<hr>

<x:forEach select="$document//book">
  -> 
  <x:choose>
  <x:when select='$document//author[@id="2"]'>
   author id=2,<x:out select='$document//author[@id="2"]'/>
   </x:when>
   <x:otherwise>
   no author's id=2
   </x:otherwise>
  </x:choose>
  <br/>
</x:forEach>


</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?