问题描述
这个是我web.xml<!-- 定义dwr拦截器 --><servlet><servlet-name>dwr</servlet-name><servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class><init-param><param-name>debug</param-name><param-value>true</param-value></init-param></servlet><servlet-mapping><servlet-name>dwr</servlet-name><url-pattern>/dwr/*</url-pattern></servlet-mapping>这个是dwr.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd"><dwr><allow><!--javascript属性对应客户端调用的JS,new表示用new创造器 --><create javascript="housejs" creator="new"><!--name="class"表示对应的是java类,value属性是对应的后台功能类 --><param name="class" value="org.shj.houseproject.house.action.HouseAction"></param><!-- method是说后台类里面的那个方法可以调用 --><include method="getstreet"></include></create><!-- 如果后台类返回的是list类型,那就要加上这句 --><convert match="org.shj.houseproject.pojo.Street"converter="bean" /></allow></dwr>这个是我JSP<tr align="left"><td align="left" class="listTitleTd">区域:</td><td><s:select id="areaid" list="listarea" listValue="aname"listKey="aid" headerKey="0" headerValue="--请选择区域--"theme="simple" multiple="false"onchange="getstreet()"></s:select></td></tr><tr align="left"><td align="left" class="listTitleTd">街道:</td><td><s:select id="street" list="#{}" listKey="sid" listValue="sname"headerKey="0" headerValue="--请选择街道--" name="house.sid"multiple="false" theme="simple"></s:select></td></tr>JS代码:<script type='text/javascript'src='/houseTest/dwr/interface/housejs.js'></script><script type='text/javascript' src='/houseTest/dwr/engine.js'></script><script type='text/javascript' src='/houseTest/dwr/util.js'></script><script type="text/javascript">function getstreet(){alert(" ");var areaid=document.getElementById("areaid").value;housejs.getstreet(areaid,getstreets_back);}//获得回调函数,名字取决于上面那行//参数data是接受的action的返回值,这个是list类型的。然后将list加载到下拉列表框中fuction getstreets_back(data){var street=document.getElementById("street");for(var i=0;i<data.length;i++){var opt=new Option(data[i].aname,data[i].value);street.options[i]=opt;}}</script>这个是我的ACTIONpackage org.shj.houseproject.house.action;import java.util.List;import org.shj.houseproject.houseService.IHouseService;import org.shj.houseproject.pojo.Area;import org.shj.houseproject.pojo.House;import org.shj.houseproject.pojo.Street;import com.opensymphony.xwork2.ActionSupport;public class HouseAction extends ActionSupport {public List getstreet(int areaid) {List<Street> liststreet = houseservice.listStreet(areaid);return liststreet;}} 问题补充:zhao_chong 写道
解决方案
你先看看dwr配置成功没
解决方案二:
二级联动最好是把数据预加载到application里,这样就不需要每次都加载首先你要检查一下dwr是否配置成功,其次就是看看js里data有没有数据