亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜索
JSP 基礎(chǔ)教程 JSP 開發(fā)環(huán)境搭建 JSP 結(jié)構(gòu) JSP 生命周期 JSP 語法 JSP 指令 JSP 動(dòng)作元素 JSP 隱式對(duì)象 JSP 客戶端請(qǐng)求 JSP 服務(wù)器響應(yīng) JSP HTTP 狀態(tài)碼 JSP 表單處理 JSP 過濾器 JSP Cookies 處理 JSP Session JSP 文件上傳 JSP 日期處理 JSP 頁面重定向 JSP 點(diǎn)擊量統(tǒng)計(jì) JSP 自動(dòng)刷新 JSP 發(fā)送郵件 JSP 高級(jí)教程 JSP 標(biāo)準(zhǔn)標(biāo)簽庫(JSTL) <c:out> 標(biāo)簽 <c:set> 標(biāo)簽 <c:remove> 標(biāo)簽 <c:catch> 標(biāo)簽 <c:if> 標(biāo)簽 <c:choose> <c:import> 標(biāo)簽 <c:forEach> <c:param> 標(biāo)簽 <c:redirect> 標(biāo)簽 <fmt:formatNumber>標(biāo)簽 <fmt:parseNumber> 標(biāo)簽 <fmt:formatDate> 標(biāo)簽 <fmt:parseDate> 標(biāo)簽 <fmt:bundle> 標(biāo)簽 <fmt:setLocale> 標(biāo)簽 <fmt:setBundle> 標(biāo)簽 <fmt:timeZone> 標(biāo)簽 <fmt:setTimeZone> 標(biāo)簽 <fmt:message> 標(biāo)簽 <fmt:requestEncoding> 標(biāo)簽 <sql:setDataSource> 標(biāo)簽 <sql:query> 標(biāo)簽 <sql:update> 標(biāo)簽 <sql:param> 標(biāo)簽 <sql:dateParam> 標(biāo)簽 <sql:transaction> 標(biāo)簽 <x:out> 標(biāo)簽 <x:parse> 標(biāo)簽 <x:set> 標(biāo)簽 <x:if> 標(biāo)簽 <x:forEach> 標(biāo)簽 <x:choose> <x:transform> 標(biāo)簽 <x:param> 標(biāo)簽 fn:contains()函數(shù) fn:containsIgnoreCase()函數(shù) fn:endsWith()函數(shù) fn:escapeXml()函數(shù) fn:indexOf()函數(shù) fn:join()函數(shù) fn:length()函數(shù) fn:replace()函數(shù) fn:split()函數(shù) fn:startsWith()函數(shù) fn:substring()函數(shù) fn:substringAfter()函數(shù) fn:substringBefore()函數(shù) fn:toLowerCase()函數(shù) fn:toUpperCase()函數(shù) fn:trim()函數(shù) JSP 連接數(shù)據(jù)庫 JSP XML 數(shù)據(jù)處理 JSP JavaBean JSP 自定義標(biāo)簽 JSP 表達(dá)式語言 JSP 異常處理 JSP 調(diào)試 JSP 國際化
文字

JSP XML 數(shù)據(jù)處理


當(dāng)通過HTTP發(fā)送XML數(shù)據(jù)時(shí),就有必要使用JSP來處理傳入和流出的XML文檔了,比如RSS文檔。作為一個(gè)XML文檔,它僅僅只是一堆文本而已,使用JSP創(chuàng)建XML文檔并不比創(chuàng)建一個(gè)HTML文檔難。


使用JSP發(fā)送XML

使用JSP發(fā)送XML內(nèi)容就和發(fā)送HTML內(nèi)容一樣。唯一的不同就是您需要把頁面的context屬性設(shè)置為text/xml。要設(shè)置context屬性,使用<%@page %?>命令,就像這樣:

<%@ page contentType="text/xml" %>

接下來這個(gè)例子向?yàn)g覽器發(fā)送XML內(nèi)容:

<%@ page contentType="text/xml" %>

<books>
   <book>
      <name>Padam History</name>
      <author>ZARA</author>
      <price>100</price>
   </book>
</books>

使用不同的瀏覽器來訪問這個(gè)例子,看看這個(gè)例子所呈現(xiàn)的文檔樹。


在JSP中處理XML

在使用JSP處理XML之前,您需要將與XML 和XPath相關(guān)的兩個(gè)庫文件放在<Tomcat Installation Directory>\lib目錄下:

  • XercesImpl.jar:在這下載http://www.apache.org/dist/xerces/j/
  • xalan.jar:在這下載http://xml.apache.org/xalan-j/http://www.shouce.ren/api/view/a/7505

books.xml文件:

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

main.jsp文件:

<%@ 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:8080/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>

訪問http://localhost:8080/main.jsp,運(yùn)行結(jié)果如下:

BOOKS INFO:
The title of the first book is:Padam History 
The price of the second book: 2000

使用JSP格式化XML

這個(gè)是XSLT樣式表style.xsl文件:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version="1.0">
 
<xsl:output method="html" indent="yes"/>
 
<xsl:template match="/">
  <html>
  <body>
   <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>
 
<xsl:template match="books">
  <table border="1" width="100%">
    <xsl:for-each select="book">
      <tr>
        <td>
          <i><xsl:value-of select="name"/></i>
        </td>
        <td>
          <xsl:value-of select="author"/>
        </td>
        <td>
          <xsl:value-of select="price"/>
        </td>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>

這個(gè)是main.jsp文件:

<%@ 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:transform 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>
 
<c:import url="http://localhost:8080/style.xsl" var="xslt"/>
<x:transform xml="${xmltext}" xslt="${xslt}"/>
 
</body>
</html>

運(yùn)行結(jié)果如下:

更多關(guān)于使用JSTL處理XML的內(nèi)容請(qǐng)查閱JSP標(biāo)準(zhǔn)標(biāo)簽庫。

關(guān)于我們 聯(lián)系我們 留言板

手冊(cè)網(wǎng)

上一篇: 下一篇: