其他分享
首页 > 其他分享> > 2021-11-08

2021-11-08

作者:互联网

解决火狐浏览器中文乱码问题

问题出现原因: 由于火狐浏览器会对中文字符进行自动转码,所以对于火狐浏览器要特殊处理

解决方法:

 String agent =request.getHeader("USER-AGENT").toLowerCase();
            if (agent.contains("firefox")) {
                response.setCharacterEncoding("UTF-8");
                response.setHeader("content-Type", "application/vnd.ms-excel");
                fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
                fileName = new String(fileName.getBytes(), StandardCharsets.ISO_8859_1.name());
                response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
                response.setHeader("Content-Disposition", "attachment;filename="+ fileName+format+".xls");
            }

标签:11,浏览器,String,08,agent,fileName,火狐,2021,response
来源: https://blog.csdn.net/blame_a/article/details/121218406