首页 > 其他 > 详细

poi导出excel名称中文乱码(对IE,chrome,Firefox有效)

时间:2016-09-05 16:51:30      阅读:376      评论:0      收藏:0      [点我收藏+]
// 判断浏览器类型,firefox浏览器做特殊处理,否则下载文件名乱码
	public static void compatibleFileName(HttpServletRequest request, HttpServletResponse response, String excelname) throws UnsupportedEncodingException {
		String agent = request.getHeader("USER-AGENT").toLowerCase();
		response.setContentType("application/vnd.ms-excel");
		String fileName = excelname;
		String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
		if (agent.contains("firefox")) {
			response.setCharacterEncoding("utf-8");
			response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls");
		} else {
			response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
		}
	}

poi导出excel名称中文乱码(对IE,chrome,Firefox有效)

原文:http://www.cnblogs.com/k-iss/p/5842607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!