//生成xml文档
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root");
root.addElement("test").addText("111");
String xml = document.asXML();
//压缩
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(out);
ZipEntry ze = new ZipEntry("test.xml");
zipOut.putNextEntry(ze);
zipOut.write(xml.getBytes());
zipOut.close();
byte[] content = out.toByteArray();
//输出
if (content != null)
{
HttpServletResponse response = getHttpResponse();
response.setContentType("application/zip; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=test.zip");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setDateHeader("Expires", System.currentTimeMillis() + 1000L);
response.getOutputStream().write(content);
}