- 论坛徽章:
- 0
|
public ActionForward onCityChange(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
try {
System.out.println("--------进入SoAction--onCityChange--------");
String cityId = request.getParameter("cityId");
List list = this.queryService.getDistrictByCityId(cityId);
request.setCharacterEncoding("GBK");
response.setContentType("text/xml;charset=GBK");
Element rootElement = new Element("reponse"); //根元素,只有一个
Document resDoc = new Document(rootElement);
TestDTO dto = new TestDTO();
for(Iterator it = list.iterator(); it.hasNext();) {
dto = (TestDTO) it.next();
Element subject = new Element("district");
rootElement.addContent(subject); //生成多个元素,挂于根元素之下
subject.addContent(new Element("id").addContent(dto.getId()));
subject.addContent(new Element("value").addContent(dto.getValue()));
}
PrintWriter out = response.getWriter();
XMLOutputter outputter = new XMLOutputter(" ", true, "GBK");
outputter.output(resDoc, out);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10945/showart_332781.html |
|