用dwr做级联下拉表单
级联下拉表单的做法有很多种,如jquery ajax,dwr等。
现在我介绍下用dwr的做法。
?
实现目标:
?
两级地域下拉表单
?A????? B
?
A中有三个选项:全部,北京,上海
当A选全部时,B中出现全部
当A选北京时,B中出现全部,朝阳区,海淀区
当A选上海时,B中出现全部,浦东区,普坨区
?
1、下载dwr-2.0.rc1.jar,放入WEB-INIF/lib,附件中有。
2、在web.xml中加入
?
?
6、新建dwr.jsp页面,
?
?
7、建一个action导向该jsp,url为:/common/dwr.html
package com.my.action;import java.util.List;import com.my.dwr.Area;import com.my.dwr.AreaService;import com.opensymphony.xwork2.ActionSupport;/** * * @author 锅巴 * @date 2011-3-6 * @description */public class Dwr extends ActionSupport{/** * */private static final long serialVersionUID = 1L;private AreaService areaService;private List<Area> parentAreas;@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubparentAreas = areaService.getParentAreas();return SUCCESS;}public List<Area> getParentAreas() {return parentAreas;}public void setAreaService(AreaService areaService) {this.areaService = areaService;}}?
?
可以访问/common/dwr.html了,试试下拉的效果