日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

使用JSP的标准标签库JSTL处理XML格式的数据

發(fā)布時間:2023/12/19 asp.net 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用JSP的标准标签库JSTL处理XML格式的数据 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

JSP標準標簽庫(JSTL)是一個JSP標簽集合,它封裝了JSP應用的通用核心功能。

下載地址:https://archive.apache.org/dist/jakarta/taglibs/standard/binaries/

下載文件jakarta-taglibs-standard-1.1.2.zip,將lib文件夾下的jstl.jar和standard.jar文件,置于JSP項目的WEB-INF/lib下。

在web.xml中添加如下內(nèi)容:

<jsp-config><taglib><taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri><taglib-location>/WEB-INF/fmt.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri><taglib-location>/WEB-INF/fmt-rt.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/core</taglib-uri><taglib-location>/WEB-INF/c.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri><taglib-location>/WEB-INF/c-rt.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/sql</taglib-uri><taglib-location>/WEB-INF/sql.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri><taglib-location>/WEB-INF/sql-rt.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/x</taglib-uri><taglib-location>/WEB-INF/x.tld</taglib-location></taglib><taglib><taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri><taglib-location>/WEB-INF/x-rt.tld</taglib-location></taglib></jsp-config>

使用任何庫,都必須在每個JSP文件中的頭部包含標簽。

在WebContent文件夾下新建一個books.xml文件,內(nèi)容如下:

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

瀏覽器里可以立即看到這個xml文件:

main.jsp的源代碼:

<%@ 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:parse Tags</title> </head> <body> <h3>Books Info:</h3> <c:import var="bookInfo" url="http://localhost:9032/jerryjsp/books.xml"/><x:parse xml="${bookInfo}" 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>

為了能夠處理xml格式的數(shù)據(jù),tomcat lib文件夾下面必須要有這些jar包:

  • xalan.jar
  • xercesImpl.jar

  • serializer.jar
  • xml-apis.jar

最后的結(jié)果:

要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":

總結(jié)

以上是生活随笔為你收集整理的使用JSP的标准标签库JSTL处理XML格式的数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。