一个关于Struts+JavaScript省市联动菜单的问题
现在要用Struts+JavaScript实现一个省市联动菜单,遇到了点问题,实现思想是这样的:
首先页面显示时,加载省的选项,然后选择省后,将省的值传到Action中,调用方法获取市的集合,再将市的集合赋值给FormBean,再将FormBean传到原JSP页面,从而达到动态效果,但是现在出了点问题,代码如下:
我有一XML文件:
<?xml version="1.0" encoding="GBK"?>
<china>
<province name="直辖市">
<city>北京</city>
<city>上海</city>
<city>天津</city>
<city>重庆</city>
</province>
<province name="广东">
<city>广州</city>
<city>珠海</city>
<city>深圳</city>
<city>东莞</city>
</province>
<province name="广西">
<city>桂林</city>
<city>柳州</city>
<city>北海</city>
<city>南宁</city>
</province>
<province name="海南">
<city>海口</city>
<city>三亚</city>
</province>
<province name="湖北">
<city>武汉</city>
<city>鄂州</city>
<city>荆州</city>
<city>十堰</city>
</province>
<province name="湖南">
<city>长沙</city>
<city>岳阳</city>
<city>常德</city>
<city>张家界</city>
</province>
<province name="浙江">
<city>杭州</city>
<city>绍兴</city>
<city>宁波</city>
<city>台州</city>
</province>
<province name="辽宁">
<city>沈阳</city>
<city>大连</city>
<city>抚顺</city>
<city>铁岭</city>
</province>
</china>
***************************************
然后通过JDOM解析,分别获取省市,
package com.selectdemo.tool;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class ReadXml {
Element root = null;
public ReadXml() throws FileNotFoundException, JDOMException, IOException {
super();
SAXBuilder sb = new SAXBuilder();//解析器对象
Document doc = sb.build(this.getClass().getResourceAsStream("/city.xml"));//绑定文件
root = doc.getRootElement();//获取根元素
}
public List getProvince(){ //获取省份
ArrayList provinceList = new ArrayList();
List tempList = root.getChildren();//获取所有省份节点
for(int i=0; i<tempList.size();i++){
Element province=(Element)tempList.get(i);//子节点转型
provinceList.add(province.getAttributeValue("name"));//获取省份节点属性内容
}
return provinceList;
}
public List getCity(String province){
ArrayList cityList = new ArrayList();
List provincetemplist = root.getChildren();//省份集合
for(int i=0; i<provincetemplist.size();i++){
Element provinceElement = (Element)provincetemplist.get(i);
if((provinceElement.getAttributeValue("name")).equals(province)){//如果属性为传进来的名称
List cityTempList = provinceElement.getChildren();//获取子节点集合
for(int j=0; j<cityTempList.size(); j++){//循环
Element cityElement = (Element)cityTempList.get(j);//当前城市节点
cityList.add(cityElement.getTextTrim());//增加城市到集合
}
}
}
return cityList;
}
}
******************************
然后JSP页面代码:
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<SCRIPT LANGUAGE="JavaScript">
function fungetCityes()
{
document.forms[0