jstl使用xml出错

jstl需要引用3个jar文件,在附件中

默认myEclipse(5.5M1)只会引用其中的2个(jstl.jar,standard.jar),需要自己添加一个 (xalan.jar)

jstl官方API

http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html

一个jstl1.1中使用xml的完整例子

测试通过环境

1. eclipse 3.2.1

2. windows server 2003

3. myEclipse5.5M1

4. tomcate 5.5

5. JDK 1.6

 

student.xml

xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <students>  
  3.    <student id="1">  
  4.       <name>  
  5.          <first name="Joe1">Joefirst>  
  6.          <last name="y1">Ylast>  
  7.          <middle name="t1">Tmiddle>  
  8.       name>  
  9.       <grade>  
  10.          <points>99points>  
  11.          <letter>Aletter>  
  12.       grade>  
  13.    student>  
  14.    <student id="2">  
  15.       <name>  
  16.          <first name="james1">Jamesfirst>  
  17.          <last name="todd">Toddlast>  
  18.          <middle name="k1">Kmiddle>  
  19.       name>  
  20.       <grade>  
  21.          <points>92points>  
  22.          <letter>Bletter>  
  23.       grade>  
  24.    student>  
  25.    <student id="3">  
  26.       <name>  
  27.          <first name="kate1">Katefirst>  
  28.          <last name="wang1">Wanglast>  
  29.          <middle name="a1">Amiddle>  
  30.       name>  
  31.       <grade>  
  32.          <points>72points>  
  33.          <letter>Cletter>  
  34.       grade>  
  35.    student>  
  36.       
  37. students>  

test.jsp 使用代码

xml 代码
  1. <%@ page language="java"  pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
  3. <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>  
  4.   
  5. <html>  
  6.   <head>  
  7.     <title>indextitle>  
  8.   head>  
  9.      
  10.   <body>  
  11.     <c:import var="students" url="student.xml" />  
  12.   
  13.     <x:parse var="doc" xml="${students}" />  
  14.   
  15.     <table border="1">  
  16.       <tr>  
  17.         <th>Firstth>  
  18.         <th>Lastth>  
  19.         <th>Pointsth>  
  20.         <th>Letterth>  
  21.       tr>  
  22.       <x:forEach var="student" select="$doc/students/student">  
  23.         <tr>  
  24.           <td>  
  25.             <x:out select="name/first/@name" />  
  26.           td>  
  27.           <td>  
  28.             <x:out select="name/last" />  
  29.           td>  
  30.           <td>  
  31.             <x:out select="grade/points" />  
  32.           td>  
  33.           <td>  
  34.             <x:out select="grade/letter" />  
  35.           td>  
  36.         tr>  
  37.       x:forEach>  
  38.     table>  
  39.        
  40.   body>  
  41. html>  

你可能感兴趣的:(eclipse,jsp,xml,MyEclipse,sun)