try { String name = quarter +"上报统计表.xlsx"; // 文件名 OutputStream os = response.getOutputStream(); // 取得输出流 response.reset(); // 清空输出流 String codedfilename = URLEncoder.encode(name, "UTF-8"); //防止文件名中文乱码 response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename); // 设定输出文件头 response.setContentType("application/msexcel");// 定义输出类型 wb.write(os); os.close(); } catch(Exception e) { e.printStackTrace(); }
OutputStream 流下载
最新推荐文章于 2024-12-12 19:59:55 发布
该博客介绍了如何在Java中使用OutputStream和HttpServletResponse来下载文件,重点在于设置正确的Content-Disposition和Content-Type,以及处理文件名的编码问题,以确保安全无乱码的下载体验。
1616

被折叠的 条评论
为什么被折叠?



