A problem with AJAX.pls!

I am learning Ajax,so I find an example from web,but I came around a problem ,and can't find the error where it is.I parse the source files here,please help me to check and point the error to me ,thanks.As follows:

JSP(ajaxsel.jsp):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>MyHtml.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="this is my page">

</head>

<script type="text/javascript">

function getResult(stateVal) {

//alert(stateVal);

var url = "servlet/SelectCityServlet?state="+stateVal;

if(window.XMLHttpRequest) {

req = new XMLHttpRequest();

}else if(window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

if(req) {

req.open("GET",url,true);

req.onreadystatechange = complete;

req.send(null);

}

}

function complete() {

if(req.readyState == 4) {

if(req.status == 200) {

alert("1");

var city = req.responseXML.getElementsByTagName("city");

//alert("city.length:"+city.length);

var srt = new Array();

for(var i=0;i<city.length;i++) {

srt = city.firstChild.data;

}

//alert("city:"+document.getElementById("city"));

buildSelect(str,document.getElementById("city"));

}

}

}

function buildSelect(srt,sel) {

sel.options.length = 0;

for(var i=0;i<srt.length;i++) {

sel.options[sel.options.length] = new Option(str,str);

}

}

></script>

<body>

<select name="state" onChange="getResult(document.all.state.options[document.all.state.selectedIndex].value)">

<option value="0">Select</option>

<option value="zj">zhejiang</option>

<option value="zs">jiangsu</option>

</select>

<select name="city">

<option vlaue="">CITY</option>

</select>

</body>

</html>

XML(web.xml):

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<servlet>

<servlet-name>SelectCityServlet</servlet-name>

<servlet-class>com.stephen.servlet.SelectCityServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>SelectCityServlet</servlet-name>

<url-pattern>/servlet/SelectCityServlet</url-pattern>

</servlet-mapping>

</web-app>

SERVLET(SelectCityServlet.java):

package com.stephen.servlet;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* @author Administrator

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

public class SelectCityServlet extends HttpServlet {

丂丂public SelectCityServlet() {

丂丂super();

丂丂}

丂丂public void destroy() {

丂丂super.destroy();

丂丂}

丂丂public void doGet(HttpServletRequest request, HttpServletResponse response)

丂丂throws ServletException, IOException {

丂丂response.setContentType("text/xml");

丂丂response.setHeader("Cache-Control", "no-cache");

丂丂String state = request.getParameter("state");

丂丂StringBuffer sb=new StringBuffer("<state>");

丂丂if ("zj".equals(state)){

丂丂sb.append("<city>hangzhou</city><city>huzhou</city>");

丂丂} else if("zs".equals(state)){

丂丂sb.append("<city>nanjing</city><city>yangzhou</city><city>suzhou</city>");

丂丂}

丂丂sb.append("</state>");

丂丂PrintWriter out=response.getWriter();

丂丂out.write(sb.toString());

丂丂out.close();

丂丂}

}

[4482 byte] By [bronze-starDukes] at [2007-11-26 12:14:18]
# 1
That's pretty hard to read, don't you think? But the main problem with your post is, all you have done is to tell us you have a problem. But you haven't said what it is. That makes it very hard for someone to think about it.
platinumsta at 2007-7-7 14:16:43 > top of Java-index,Archived Forums,Socket Programming...
# 2

Thanks for your tip!

Yes,first I should descript the program.There is a select,name is state,having two citys.Their value are zj and zs.For example,when you select zj,the other select ,name is city,displaying the citys:hangzhou and

huzhou.But there are no errors to tell me,and when I select an option,javascript has no error and the second select displays nothing.So I can't find the error where it is.

bronzestar at 2007-7-7 14:16:43 > top of Java-index,Archived Forums,Socket Programming...