首页 > 编程语言 > 详细

java实现通过浏览器下载文件

时间:2020-12-01 11:23:17      阅读:661      评论:0      收藏:0      [点我收藏+]

 

OutputStream output;
        try {
            output = response.getOutputStream();
            //清空缓存
            response.reset();
            //定义浏览器响应表头,顺带定义下载名,比如students(中文名需要转义)
            String s = file.getName() + file.getBirthday();
            response.setHeader("Content-disposition", "attachment;filename=" + new String(s.getBytes(), "iso-8859-1") + ".xls");
            //定义下载的类型,标明是excel文件
            response.setContentType("application/vnd.ms-excel");
            //这时候把创建好的excel写入到输出流
            wb.write(output);
            //养成好习惯,出门记得随手关门
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

 

java实现通过浏览器下载文件

原文:https://www.cnblogs.com/zagwk/p/14066519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!