出现的问题:在chrome浏览器中导出的excel文件名没有出现中文乱码的情况,在测试IE浏览器的时候,导出的文件名乱码了。解决方法:原来的代码:try { response.setContentType("appl
出现的问题:在chrome浏览器中导出的excel文件名没有出现中文乱码的情况,在测试IE浏览器的时候,导出的文件名乱码了。
解决方法:
原来的代码:
try {
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + new String((edTemplate.getTemplateName() + "导入模板").getBytes(), "ISO-8859-1") + ".xls");
OutputStream os = response.getOutputStream();
workbook.write(os);
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
return ResponseMsgUtil.failure();
}
在new String((edTemplate.getTemplateName() + "导入模板").getBytes(), "ISO-8859-1") 的getBytes()这个方法里加上一个编码
修改后的代码
try {
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + new String((edTemplate.getTemplateName() + "导入模板").getBytes("gb2312"), "ISO-8859-1") + ".xls");
OutputStream os = response.getOutputStream();
workbook.write(os);
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
return ResponseMsgUtil.failure();
}
--结束END--
本文标题: java导出文件出现文件名乱码解决方法
本文链接: https://www.lsjlt.com/news/2130.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0