当前位置:网站首页>[The browser opens the exported excel]
[The browser opens the exported excel]
2022-08-08 21:02:00 【child running in the sun】
public void setResponseHeader(HttpServletResponse response,String filePath) {
try {
File file = new File(filePath);
String filename = file.getName();
if( !file.exists()){
return;
}
response.reset();
FileInputStream fileInput = new FileInputStream(file);
OutputStream outPut = response.getOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = fileInput.read(buffer)) > 0){
outPut.write(buffer, 0, len);
}
fileInput.close();
response.addHeader("Content-Disposition", "attachment;filename=" +new String(filename.getBytes("UTF-8"), "utf-8"));
response.addHeader("Content-Length", "" + file.length());
response.setContentType("application/x-msdownload");
} catch (IOException ex) {
ex.printStackTrace();
return;
}
}
边栏推荐
猜你喜欢
随机推荐
pm2安装配置与基本命令你知道吗?
OneNote 教程,如何在 OneNote 中检查拼写?
关于KotlinAndroid遇到的小知识
【idea_取消自动import .*】
Kotlin reflection
怎样在网上开户买股票比较安全?如何办理开户业务?
Kotlin注解
Mysql management commands
单片机——串口通信(从串口接收多位数据保存到数组,发送多位数据到串口)
IO in Kotlin flow
Kotlin study notes
【梦想的声音】
阿里云祝顺民:算力网络架构的新探索
1天搞定单片机中断——基础知识大全
amd和Intel的CPU到底哪个好?
内网渗透之代理转发
学习笔记:栈的应用1_递归(重点)
第06篇 MEF部件的生命周期(PartCreationPolicy)
rancher -部署
昇腾Ascend 随记 —— 昇腾 AI 的基本架构