问题描述
在Safari中,我的CSV文件正在浏览器中显示,而不是使用另存为窗口下载。
In Safari, my CSV files are being shown in the browser instead of downloading them using the Save As window.
我试过: .setContentType(text / csv; charset = UTF-8);
。其他浏览器与第二个选项很好,但Safari一直在浏览器中显示文件,而不是提示用户保存它。
I tried: response.setContentType("text/csv; charset=UTF-8");
. The other browsers are fine with the second option, but Safari kept displaying the file in-browser instead of prompting the user to save it.
顺便说一句,运行Liferay。
By the way, i'm running Liferay.
我通过添加以下内容修复了它:response.setContentType(application / csv; charset = UTF-8);
I fixed it by including this: response.setContentType("application/csv; charset=UTF-8");
感谢。
推荐答案
text / csv
将是最适合的内容类型。你还想像这样设置content-disposition:
text/csv
would be the most appropriate for the content type. You also want to set the content-disposition like this:
response.setHeader( "Content-Disposition", "attachment;filename=" + filename );
这篇关于如何让Safari下载CSV而不是在浏览器中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!