当前位置: 首页 > 工具软件 > AjaxTags > 使用案例 >

java 省级下拉列表_省份城市下拉列表(AjaxTags+hibernate+spring)

殷安顺
2023-12-01

target="province"

baseUrl="../area.do"

parameters="areaName={country}"/>

target="city"

baseUrl="../area.do"

parameters="areaName={province}"/>

AreaServlet.java

package dgut.ke.servlet;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.ajaxtags.helpers.AjaxXmlBuilder;

import org.ajaxtags.servlets.BaseAjaxServlet;

import org.springframework.web.context.support.WebApplicationContextUtils;

import dgut.ke.model.Area;

import dgut.ke.util.AreaUtil;

@SuppressWarnings("serial")

public class AreaServlet extends BaseAjaxServlet {

@SuppressWarnings("unchecked")

@Override

public String getXmlContent(HttpServletRequest request,

HttpServletResponse response) throws Exception {

request.setCharacterEncoding("UTF-8");

AreaUtil areaUtil = (AreaUtil) WebApplicationContextUtils

.getRequiredWebApplicationContext(getServletContext())

.getBean("areaUtil");

String areaName = request.getParameter("areaName");

//将areaName转换成areaCode

String parentAreaCode = areaUtil.findAreaCodeByAreaName(areaName);

if(parentAreaCode != null && ! parentAreaCode.equals("")) {

List list = areaUtil.findByParentAreaCode(parentAreaCode);

AjaxXmlBuilder builder = new AjaxXmlBuilder();

for(Area area : list) {

builder = builder.addItem(area.getAreaName(), area.getAreaName());

}

return builder.toString();

} else {

return null;

}

}

}

Servlet配置

areaServlet

dgut.ke.servlet.AreaServlet

areaServlet

/area.do

 类似资料: