Oops! JSP + XML Quick Start
/Files/pixysoft/xalan.part1.rar
/Files/pixysoft/xalan.part2.rar
新建一个Dynamic Web Project,名叫Oops_jsp_xml,然后在lib下添加以下jar文件,都可以在JSTL包里面找到。(xalan.jar文件这里下载,解压出来)。在WEB-INF下新建tlds目录,添加c.tld文件。
修改web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
在WebContent目录下面添加2个文件:
student.xml
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student id="1">
<name>
<first name="Joe1">Joe</first>
<last name="y1">Y</last>
<middle name="t1">T</middle>
</name>
<grade>
<points>99</points>
<letter>A</letter>
</grade>
</student>
<student id="2">
<name>
<first name="james1">James</first>
<last name="todd">Todd</last>
<middle name="k1">K</middle>
</name>
<grade>
<points>92</points>
<letter>B</letter>
</grade>
</student>
<student id="3">
<name>
<first name="kate1">Kate</first>
<last name="wang1">Wang</last>
<middle name="a1">A</middle>
</name>
<grade>
<points>72</points>
<letter>C</letter>
</grade>
</student>
</students>
index.jsp
<%@ page language="java" 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>index</title>
</head>
<body>
<c:import var="students" url="student.xml" />
<x:parse var="doc" xml="${students}"/>
<table border="1">
<tr>
<th>First</th>
<th>Last</th>
<th>Points</th>
<th>Letter</th>
</tr>
<x:forEach var="student" select="$doc/students/student">
<tr>
<td><x:out select="name/first/@name" /></td>
<td><x:out select="name/last" /></td>
<td><x:out select="grade/points" /></td>
<td><x:out select="grade/letter" /></td>
</tr>
</x:forEach>
</table>
</body>
</html>
运行!
posted on 2007-09-02 02:21
张辰 阅读(239)
评论(0) 编辑 收藏 所属分类:
Dr. Oops