a0c584452806001c1a55d0db498a726f

来自「Internet 开发技术分章节代码和自己完成的课程设计全代码(在zuoye文件」· 代码 · 共 60 行

TXT
60
字号
ch12-xmltag.jsp的JSP文件,在这个文件中输入下述代码:
<%@ 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实例</title>
</head>
<body bgcolor="#FFFFFF">
<h3>JSTL-XML实例: Parse和ForEach</h3>

<x:parse var="document">
   <GetAllBooks>
      <book id="MyBook">
		<name>Book Name:Web应用开发技术JSP</name>
		<publisher>publisher:西安电子科技大学出版社</publisher>
		<address>address:西安市</address>
		<category>category:计算机</category>
		<description>description:JSP开发技术的新书</description>
		<authors>
	      <author id="65321">
	          <name> author Name:崔尚森</name>
		  </author>
	      <author id="65322">
		      <name>another author Name:张白一</name>
		  </author>
		</authors>
     </book>
  </GetAllBooks>        
</x:parse>
使用forEach 全部输出:<hr/>
<x:forEach select="$document/GetAllBooks">
   <x:out select="."/>
   <br/>
</x:forEach>

<hr/> 在forEach中使用if输出作者名:
<x:forEach select="$document//book">
  <x:if select=".//author">
   <x:out select=".//author/name"/>
  </x:if>
  <br/>
</x:forEach>

<hr/>在forEach中使用choose输出作者名:<br/>
<x:forEach select="$document//book">
  <x:choose>
  <x:when select='$document//author[@id="65322"]'>
   使用choose的when输出作者之一:<x:out select='$document//author[@id="65322"]'/>
   </x:when>
   <x:otherwise>
   使用choose的otherwise输出作者之一:<x:out select='$document//author[@id="65321"]'/>
   </x:otherwise>
  </x:choose>
  <br/>
</x:forEach>
</body>
</html>

⌨️ 快捷键说明

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