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");
            }
上一篇:2021-11-08


下一篇:2021-11-08