public class BatchDownloadServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment;filename=test.zip");
String path = getServletContext().getRealPath("/")+"images/";
String[] filenames = request.getParameterValues("filename");
String str = "";
String rt = "\r\t";
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
for(String filename:filenames){
str+=filename+rt;
File file = new File(path+filename);
zos.putNextEntry(new ZipEntry(filename));
FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[1024];
int n = 0;
while((n=fis.read(b))!=-1){
zos.write(b, 0, n);
}
zos.flush();
fis.close();
}
zos.setComment("download success:"+rt+str);
zos.flush();
zos.close(); } }

最新文章

  1. CentOS 新增swap交换空间
  2. 列表边框column-rule
  3. C语言-预估校正法求常微分方程
  4. loadrunner关联和事务
  5. MySQL连接查询的简单概括+思维导图
  6. Keepalived高可用集群搭建(转载linuxIDC)
  7. 关闭“JDK自动更新”提示
  8. <video>和<audio>标签
  9. 加载dll、lib库
  10. Scut 进阶:网络模型拓扑
  11. Hadoop-2.7.1集群环境搭建
  12. DBHerperl类
  13. js 实现倒计时效果
  14. MYSQL使用PMM进行性能监控
  15. Linux系统修改日期时间
  16. DeepLearning.ai-Week3-Autonomous driving-Car detection
  17. mongoose之操作mongoDB数据库
  18. BUILDING WITH BOOTSTRAP
  19. sscanf的字符串格式化用法
  20. springboot 整合swagger-ui

热门文章

  1. CSS 垂直居中。
  2. IT公司100题-10-翻转句子中单词的顺序
  3. 解决python version 2.7 required,which was not find in the registry
  4. Linux内核-模块编译和安装
  5. xampp笔记
  6. PAT 10-2 删除字符串中的子串
  7. hdu 2082
  8. LeetCode----3 Sum
  9. JQuery源码分析(四)
  10. Chocolate_DP