解析 XML时代码 错误。。这提醒是何意??

<%@ page language="java" import="java.util.*,java.text.*,java.io.*,java.util.Enumeration"

contentType="text/html; charset=utf-8"%>

<%@ page import="org.jdom.input.*"%>

<%@ page import="org.jdom.*"%>

<%

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>


<title>'JDomSAX解析XML</title>

</head>


<body>

<%

SAXBuilder builder = new SAXBuilder();

String pathStudents = request.getRealPath("students.xml");

Document doc = builder.build(pathStudents);

Element root = doc.getRootElement();


List children = root.getChildren();

String output = "<table border='1'>";

output += "<tr><td>姓名</td><td>学号</td><td>年龄</td><td>性别</td></tr>";

for (int i = 0; i < children.size(); i++) {

Element node = (Element) children.get(i);

Attribute attr = node.getAttribute("id");

output+="<tr><td>"+attr.getIntValue()+"</td>";

output+="<td>"+node.getChildText("name")+"</td>";

output+="<td>"+node.getChildText("age")+"</td>";

output+="<td>"+node.getChildText("gender")+"</td>";

output+="</tr>";


}

output+="</table>";

out.print(output);

%>

<br>

</body>

</html>

http://img.mukewang.com/5729f3fd0001dd5d07340563.jpg

qq_慕斯9291570
浏览 1723回答 2
2回答

Jamespan

这不是传说中的空指针异常嘛

ziom

空指针,有对象没创建就使用了吧
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java