导出文件中文乱码处理
导出文件中文乱码
/** * 下载文件名中含有中文的处理 * @param req * @param headName * @return * @throws UnsupportedEncodingException */ public static String encodeFileName(HttpServletRequest req, String headName) throws UnsupportedEncodingException { String filename=""; String header = req.getHeader("User-Agent"); if (header.toUpperCase().indexOf("MSIE") >= 0 || (header.toUpperCase().indexOf("TRIDENT") >= 0 && header.toUpperCase().indexOf("RV") >= 0)) { filename = URLEncoder.encode(headName, "UTF-8"); }else if (header.indexOf("Mozilla") >= 0) { filename = new String(headName.getBytes("UTF-8"), "ISO8859-1"); }else { filename = URLEncoder.encode(headName, "UTF-8"); } return filename; }