日期:2014-05-18 浏览次数:20637 次
private void outPutXml2(String xml) throws IOException, SAXException, ParserConfigurationException{
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out;
out = response.getWriter();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
out.write(xml);
}
public void getCities() throws Exception {
List citys = this.userService.getCities(this.user);
Document doc = DocumentHelper.createDocument();
Element rootElmt = DocumentHelper.createElement("result");
doc.add(rootElmt);
Element psElmt = DocumentHelper.createElement("cities");
rootElmt.add(psElmt);
psElmt.addAttribute("size", String.valueOf(citys.size()));
for(Object city : citys){
psElmt.add(new DOMElement("city").addText(String.valueOf(city)));
}
this.outPutXml2(this.prettyXml(doc).getBuffer().toString());
}
response.setContentType("text/xml;charset=UTF-8");
Cache-Control:no-cache
Content-Length:111
Content-Type:text/xml;charset=ISO-8859-1
Date:Sat, 30 Nov 2013 02:09:37 GMT
Server:Apache-Coyote/1.1
<action name="getCities" class="com.bang.action.XMLAction" method="getCities">
<result name="xmlMessage" type="plainText">
<param name="charSet">UTF-8</param>
</result>
</action>