当前位置:网站首页>[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;
}
}边栏推荐
猜你喜欢
随机推荐
新库上线 | CnOpenDataA股上市公司基本信息数据
常见的病毒(攻击)分类
Kotlin笔记-ForEach与ForEachIndexed区别
Kotlin实用的一些框架
Kotlin parsing String path knowledge
Kotlin study notes
【idea_取消自动import .*】
【梦想的声音】
C#版网络对战五子棋以及Socket通信
SQL-堆叠注入(含例题)
Flask 教程 第七章:错误处理
GeoServer入门学习:03-快速入门
Educational Codeforces Round 112 D. Say No to Palindromes
Kotlin delegate property knowledge points
Redis Bloom Filter
Kotlin's JSON format parsing
安装sentry
【访问本地项目,localhosthost可以,本地ip不可以】
ssh 登录connectction reset by peer
Gradle简单到使用kotlin编写到常用命令








