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