jsp缺少对象问题
一个教程上的例子,一直报缺少对象错误,麻烦帮看看哪儿的问题,谢谢!
jsp文件:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ajax基础教程 动态创建结果表</title>
<script type="text/javascript">
var ajax = null;
function initAjax(){
if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
}
}
function doit(){
initAjax();
ajax.onreadlystatechange = handstatechange;
ajax.open("GET","simple02.xml",true);
ajax.send(null);
}
function handstatechange(){
if(ajax.readyState==4){
if(ajax.status==200){
clearResults();
paresResults();
}
}
}
function clearResults(){
var header = document.getElementById("header");
if(header.hasChildNodes){
header.removeChild(header.childNodes[0]);
}
var ttbody = document.getElementById("resultsBody");
while(ttbody.childNodes.length>0){
ttbody.removeChild(ttbody.childNodes[0]);
}
}
function paresResults(){
var results = ajax.responseXML;
var property = null;
var address ="";
var price = "";
var comment = "";
var properties = results.getElementsByTagName("property");
for(int i=0;i<properties.length;i++){
property = properties[i];
address = property.getElementsByTagName("address")[0].firstChild.nodeValue;
price = property.getElementsByTagName("price")[0].firstChild.nodeValue;
comment = property.getElementsByTagName("comment")[0].firstChild.nodeValue;
addTableRow(address,price,comment);
}
var header = document.createElement("h2");
var headerText = document.createTextNode("results:");
header.appendChild(headerText);
document.getElementById("header").appendChild(header);
document.getElementById("resultsTable").setAttribute("border",1);
}
function addTableRow(address,price,comment){
var row = document.createElement("tr");
var cell = createCell(adress);
row.appendChild(cell);
cell = createCell(price);
row.appendChild(cell);
cell = createCell(comment);
row.appendChild(cell);
document.getElementById("resultsTable").appendChild(row);
}
function createCell(text){
var cell = document.createElement("td");
var textNode = document.createTextNode(text);
cell.appendChild(textNode);
return cell;
}
function test(){
alert("1111");
}
</script>
</head>
<body>
<form action="#">
<select>
<option>
dgdfddf
</option>
<option>
34
</option>
<option>
bfddf
</option>
</select>
<select>
<option>
fdffd
</option>
<option>
333
</option>
<option>
bbdc
</option>
</select>
<input type="button" value="search" onclick="doit();" />
</form>
<span id="header"></span>
<table id="resultsTable">
<tbody id="resultsBody"></tbody>
</table>
</body>
</html>
simple02.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property>
<address>address1</address>
<price>44</price>
<comment>dkal,die,dlll</comment>
</property>
<property>
<address>address2</address>
<price>66</price>
<comment>3jj,dkf,lak</comment>
</property>
<property>
<address>address3</address>
<price>88</price>
<comment>jkkd,iiekk,dll</comment>
</property>
</properties>