0
我试图从服务器上使用spring下载一个xlsx文件。文件获取下载,但它显示一个警告文件已损坏!为什么从服务器下载Excel(xlsx)文件后,文件已损坏,无法打开?
这里是我的代码:
File file = new File(outputPath+ fileName);
FileInputStream fis = new FileInputStream(file);
response.setContentType("application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet");
response.setContentLength((int) file.length());
response.setHeader("Content-Disposition", "attachment; filename="+fileName);
FileCopyUtils.copy(fis, response.getOutputStream());
JSP页面:
$("#download").click(function(){
if($(this).data('clicked', true)){
window.location="http://localhost:8080/IRI-AXCO/downloadFile";
}
}
这里是快照:
帮助表示赞赏!由于
显示完整的控制器方法。 –
嗨,我得到了解决方案,我将contenttype更改为CSV格式',谢谢你的回复 –