如何在 JSP 中列印 XPath 表示式結果?


<x:out> 標籤顯示 XPath 表示式的結果。它與 <%= %> JSP 語法具有相同的功能。

屬性

<x:out> 標籤具有以下屬性 −

屬性描述必需預設
select通常使用 XPath 變數,將 XPath 表示式作為字串求值
escapeXml如果該標籤應轉義 XML 特殊字元,則為 Truetrue

示例

我們來看一個示例,介紹標籤 (a) <x:out>、(b) <x:parse>

<%@ 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:out Tags</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"/>
      <b>The title of the first book is</b>:
      <x:out select = "$output/books/book[1]/name" />
      <br>
      <b>The price of the second book</b>:
      <x:out select = "$output/books/book[2]/price" />
   </body>
</html>

以上程式碼將生成以下結果 −

Books Info:
The title of the first book is: Padam History
The price of the second book: 2000

更新於:30-Jul-2019

294 次瀏覽

開啟您的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.