Struts1.2+DWR1.x实现省市联动的问题
这几天遇到个问题,Struts1.2+DWR1.x从数据库查询数据实现省市联动,直接访问工程名/dwr后进入相关的方法,输入参数后执行总返回null,不知道哪里出了问题,希望各位高手帮忙看看,谢谢!------------------------------------------------------------------------------------
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
uk.ltd.getahead.dwr.DWRServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
------------------------------------------------------------------------------------
dwr.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="getCity">
<param name="class" value="com.tsingyuan.pss.baseDataService.dataManageService.StoreHouseService" />
</create>
<convert converter="bean" match="com.tsingyuan.pss.bean.HrmcityId">
<param name="include" value="id,cityname" />
</convert>
</allow>
</dwr>
------------------------------------------------------------------------------------
查询省的代码就不写了,下面是查询城市的,根据select选择的id来查询
public List getCityByPID(long pid)
{
List ls = null;
String sql = "SELECT c.* FROM city c WHERE c.pid = "+pid+" ORDER BY c.cid";
ls = baseDao.queryBySQL(sql);
return ls;
}
------------------------------------------------------------------------------------
前台jsp页面相关内容
function chg(val)
{
getCity.getCityByPID(val,myback);
}
function myback(data)
{
DWRUtil.removeAllOptions("city");
DWRUtil.addOptions("city", data,"id","cityname");
}
------------------------------------------------------------------------------------
<tr>
<td align="center">省份</td>
<td><select name="province" id="province" onChange="chg(this.value)">
<logic:iterate id="pro" name="provincedata" scope="request">
<option value="${pro[0]}">${pro[1]}</option>
</logic:iterate>
</select>
</td>
</tr>
<tr>
<td align="center">城市</td>
<td><select name="city" id="city">
</select></td>
</tr>
------------------------------------------------------------------------------------
调试了很久总是返回的null,不知是哪里出问题了,望各位帮忙看看! --------------------编程问答-------------------- 帮顶... --------------------编程问答-------------------- 选择省后总是弹出null,好郁闷,各位大侠帮忙看看~ --------------------编程问答-------------------- 接分 --------------------编程问答-------------------- 你配置对了吗,debug到后台,看看后台 getCity.getCityByPID 取到值了没,如果取到了,看看是list或者array类型的吗,alert出来看看。 --------------------编程问答-------------------- <create creator="new" javascript="getCity"> new 改为spring
补充:Java , Web 开发