二级联动菜单实现(比如选择地区之后后面的城市下拉框出现相对应的城市)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/util/taglib.jsp" %>






添加精准数据











































































































上述界面里面的地域和城市是二级联动的

下面对应js方法里面的${pageContext.request.contextPath }/exactinfo.do?action=liandong&id="+escape(zhi);请求对应的后台Action里面的方法:

	/**
* 区域二级联动菜单
* @param mapping
* @param form
* @param request
* @param response
*/
public void liandong(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
response.setContentType("text/xml");
response.setHeader("Cache-Control","no-cache");
response.setCharacterEncoding("utf-8");

String id = this.getParameter("id");
String xml_start="";
String xml_end="
";
String xml="";
String hql = " from ExactArea ea where 1=1 ";
String condition = "";
Map parms = new HashMap();
if (!"".equals(id)) {
condition = " and ea.pid = :pid";
parms.put("pid", Integer.parseInt(id));
}
List areaList = dao.findAll(hql, condition, parms);
if (null != areaList && areaList.size() > 0) {
for (int i = 0; i < areaList.size(); i++) {
ExactArea area = areaList.get(i);
xml += "";
}
}
String last_xml=xml_start+xml+xml_end;
try {
// 响应返回代码
response.getWriter().write(last_xml);
} catch (IOException e) {
e.printStackTrace();
}
}

你可能感兴趣的:(jsp)