zoukankan      html  css  js  c++  java
  • smartUpload组件批量下载

    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 = "
    	";
            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();
            
        }
    
    }
  • 相关阅读:
    pyinstaller安装和使用
    django项目结构和运行项目
    安装django and 创建项目
    浅谈网络请求基础(理论篇)
    浅谈爬虫初识
    判断是否AVL平衡二叉书
    用递归方法判断两棵树是否相等
    广度优先搜索求树的深度
    堆排序
    归并排序
  • 原文地址:https://www.cnblogs.com/james-roger/p/4981643.html
Copyright © 2011-2022 走看看