码迷,mamicode.com
首页 > 其他好文 > 详细

smartUpload组件批量下载

时间:2015-11-20 19:11:13      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

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();
        
    }

}

 

smartUpload组件批量下载

标签:

原文地址:http://www.cnblogs.com/james-roger/p/4981643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!