public static void setDownloadHeader(String downloadFileName, HttpServletRequest request, HttpServletResponse response, boolean isDirectDownload) { try { if (PatternUtil.isBlank(downloadFileName)) { return; } String fileType = downloadFileName.substring(downloadFileName.lastIndexOf(".") + 1).toLowerCase(); response.setCharacterEncoding("UTF-8"); String userAgent = request.getHeader("User-Agent").toLowerCase(); if (PatternUtil.isImageFile(downloadFileName) && !isDirectDownload) { if (userAgent.indexOf("msie") != -1) { response.setContentType("application/octet-stream"); } else { response.setContentType("image/" + fileType); } } else { response.setContentType("application/octet-stream"); if (downloadFileName.length() > 70) { downloadFileName = new StringBuilder().append(downloadFileName.substring(0, 10)).append("....") .append(fileType).toString(); } if (userAgent.indexOf("firefox") != -1) { response.setHeader("Content-Disposition", new StringBuilder() .append("attachment; filename*=utf8''") .append(URLEncoder.encode(downloadFileName, "UTF-8")).toString()); } else if (userAgent.indexOf("safari") != -1) { response.setHeader("Content-Disposition", new StringBuilder().append("attachment; filename=") .append(new String(downloadFileName.getBytes("UTF-8"), "ISO8859-1")).toString()); } else { response.setHeader("Content-Disposition", new StringBuilder().append("attachment; filename=") .append(URLEncoder.encode(downloadFileName, "UTF-8")).toString()); } } } catch (UnsupportedEncodingException e) { logger.error("set download header error!", e); } }
相关推荐
Visual C++源代码 190 如何使用自动化导出Word文件Visual C++源代码 190 如何使用自动化导出Word文件Visual C++源代码 190 如何使用自动化导出Word文件Visual C++源代码 190 如何使用自动化导出Word文件Visual C++源...
Visual C++源代码 194 如何使用剪贴板导出Excel文件Visual C++源代码 194 如何使用剪贴板导出Excel文件Visual C++源代码 194 如何使用剪贴板导出Excel文件Visual C++源代码 194 如何使用剪贴板导出Excel文件Visual ...
Word文档导出,生成的word文档。 解压java2word文件,用MyEclipse导入压缩后的文件
Oracle 导入错误IMP-00010:不是有效的导出文件,头部验证失败,内含操作说明
IMP-00010:不是有效的导出文件,头部验证失败
excel导出
使用了一个高手的原有DEMO改造而成,优化了导出复杂表头增加样式过慢的问题。
java示例代码,导出pdf文件,加签;可以实现导出pdf的图片签名;导出图片,文件,内容.纯后端代码,代码示例 在项目开发中,产品的需求越来越奇葩啦,开始文件下载都是下载为excel的,做着做着需求竟然变了,要求能导出pdf...
jQuery一键导出Excel表格文件代码,一键导出.可导出excel
C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出excel代码C# 导出...
Visual C++源代码 173 如何把水晶报表导出到Excel文件Visual C++源代码 173 如何把水晶报表导出到Excel文件Visual C++源代码 173 如何把水晶报表导出到Excel文件Visual C++源代码 173 如何把水晶报表导出到Excel文件...
Visual C++源代码 195 如何使用自动化导出Excel文件Visual C++源代码 195 如何使用自动化导出Excel文件Visual C++源代码 195 如何使用自动化导出Excel文件Visual C++源代码 195 如何使用自动化导出Excel文件Visual ...
java导出文件文件名处理
导出文件列表命令
IDEA开发工具推荐,非全量部署导出更方便!
Jmeter导出文件.jmx
idea按路径导出,与eclipse导出功能类似,选择文件右键选择Export Files进行文件导出。 https://blog.csdn.net/qq_34316431/article/details/89451039
Excel选中数据进行导出时不需要导出表头。
mysql导出数据文件 mysql导出数据文件 数据库
c# 将数据库中的表显示到DATAGRIDVIEW控件中,并导出到EXCEL