新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)JSP教程:JSPXML數(shù)據(jù)處理
當通過HTTP發(fā)送XML數(shù)據(jù)時,就有必要使用JSP來處理傳入和流出的XML文檔了,比如RSS文檔。作為一個XML文檔,它僅僅只是一堆文本而已,使用JSP創(chuàng)建XML文檔并不比創(chuàng)建一個HTML文檔難。

使用JSP發(fā)送XML
使用JSP發(fā)送XML內(nèi)容就和發(fā)送HTML內(nèi)容一樣。唯一的不同就是您需要把頁面的context屬性設置為text/xml。要設置context屬性,使用<%@page % >命令,就像這樣:
<%@ page contentType="text/xml" %>
接下來這個例子向瀏覽器發(fā)送XML內(nèi)容:
<%@ page contentType="text/xml" %>
Padam History
ZARA
100
使用不同的瀏覽器來訪問這個例子,看看這個例子所呈現(xiàn)的文檔樹。
在JSP中處理XML
在使用JSP處理XML之前,您需要將與XML 和XPath相關的兩個庫文件放在
- XercesImpl.jar:在這下載http://www.apache.org/dist/xerces/j/
- xalan.jar:在這下載http://xml.apache.org/xalan-j/index.html
books.xml文件:
Padam History
ZARA
100
Great Mistry
NUHA
2000
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" %> JSTL x:parse Tags Books Info:
The title of the first book is:
The price of the second book: 訪問http://localhost:8080/main.jsp,運行結果如下:
BOOKS INFO:
The title of the first book is:Padam History
The price of the second book: 2000
使用JSP格式化XML
這個是XSLT樣式表style.xsl文件:
這個是main.jsp文件:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
JSTL x:transform Tags
Books Info:
Padam History
ZARA
100
Great Mistry
NUHA
2000
運行結果如下:
更多關于使用JSTL處理XML的內(nèi)容請查閱JSP標準標簽庫。
分享題目:創(chuàng)新互聯(lián)JSP教程:JSPXML數(shù)據(jù)處理
網(wǎng)頁URL:http://www.dlmjj.cn/article/dppgodg.html


咨詢
建站咨詢
