解决Struts2文件下载文件名中文乱码

Struts配置:


	<result name="exNoticeToExcel" type="stream">
		<param name="contentType">application/vnd.ms-excel;charset=ISO8859-1</param>
		<param name="inputName">inputStream</param>
		<param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
		<param name="bufferSize">5120</param>
	</result>


Java key code:


//使用系统时间生成字符串
	Date date = new Date();
	String nowStr = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
	String fileNameChine="通知详情导出"+nowStr+".xls";
	if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
		this.downloadFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(fileNameChine.getBytes("UTF-8")))) + "?=";   
	} else{
		this.downloadFileName = java.net.URLEncoder.encode(fileNameChine, "UTF-8");
	}


你可能感兴趣的:(struts,乱码)