主要用的是org.apache.tools.zip.ZipOutputStream 这个zip流,这里以Execl为例子。

思路首先把zip流写入到http响应输出流中,再把excel的流写入zip流中(这里可以不用生成文件再打包,只需把execl模板读出写好数据输出到zip流中,并为每次的流设置文件名)
例如:在项目webapp下execl文件中 存在1.xls,2.xls,3.xls文件
1.Controller
@RequestMapping(value = "/exportAll",method = RequestMethod.GET)
public void exportAll() throws IOException{
try {
HttpServletResponse response=this.getResponse();
response.setContentType("application/octet-stream");
String execlName = "报表";
response.addHeader("Content-Disposition", "attachment;filename="+new String(execlName.getBytes(),"iso-8859-1") +".zip");
OutputStream out = response.getOutputStream();
testService.exportAll(out);
} catch (Exception e) {
....
}
}