将xml文件在页面中良好的显示
我的查询结果是xml形式的,想把它以一种良好的形式显示在jsp页面中,该怎么做呢?
楼主的意思是在xml里面取数据么?如果是这样的话,建议用数据岛,举个例子:
MyXml.xml
<?xml version="1.0" encoding="UTF-8"?>
<class>
<student>
<name>LiMing</name>
<age>22</age>
<sex>male</sex>
</student>
<student>
<name>Lucy</name>
<age>19</age>
<sex>female</sex>
</student>
<student>
<name>Jack</name>
<age>25</age>
<sex>male</sex>
</student>
</class>
showxml.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'showxml.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<xml id="stu" src="MyXml.xml"></xml>
<h2>学生信息管理</h2>
<table datasrc=#stu border="1">
<thead>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</thead>
<tr>
<td>
<div datafld="name" > </div>
</td>
<td>
<div datafld="age" /> </div>
</td>
<td>
<div datafld="sex" /> </div>
</td>
</tr>
</table>
</body>
</html>
我这里显示用的是table,关于美工上的我就不做了,楼主可以用CSS好好装饰下~~