【转】解决safari导出excel中文名称乱码问题

        String name = "产品与企业查询.xls";  
        String userAgent = request.getHeader("User-Agent");  
        byte[] bytes = userAgent.contains("MSIE") ? name.getBytes() : name.getBytes("UTF-8"); // name.getBytes("UTF-8")处理safari的乱码问题  
        name = new String(bytes, "ISO-8859-1"); // 各浏览器基本都支持ISO编码  
        response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", name));
        response.setHeader("Content-Disposition", "attachment;filename="+name);
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/OCTET-STREAM;charset=UTF-8");
        OutputStream out;
        try {
            out = response.getOutputStream();
            wb.write(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

 参考博客:http://f0rb.iteye.com/blog/1308579

猜你喜欢

转载自girl-luo.iteye.com/blog/2338306