
出现的问题:在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()这个方法里加上一个编码
立即学习“Java免费学习笔记(深入)”;
修改后的代码
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();
        }以上就是java导出文件出现文件名乱码解决方法的详细内容,更多请关注php中文网其它相关文章!
                        
                        java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号