Java技巧:AJAX向Response留中输出Xml的办法
public static void outPrint(Document doc, HttpServletResponse response) throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=utf-8");
PrintWriter out = response.getWriter();
OutputFormat format = OutputFormat.createCompactFormat();
//去掉xml头
//format.setSuppressDeclaration(true);
//format.isPadText();
format.setEncoding("utf-8");
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
writer.flush();
writer.close();
}
转:
我之前忘记设置这个,最后不能在页面显示出xml内容。(下次要记住!)
response.setContentType("text/xml; charset=utf-8");
猜你在找