首先xml文件
<result type="stream">
<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${name}"</param>
<!-- 指定下载文件的缓冲大小 -->
<param name="bufferSize">4096</param>
</result>
然后重点来了,对文件名进行编码
HttpServletRequest request = ServletActionContext.getRequest();
String agent = request.getHeader("User-Agent");
if (null != agent) {
agent = agent.toLowerCase();
if (agent.indexOf("firefox") != -1) {
name = new String(name.getBytes(),"iso-8859-1"); //如果是火狐浏览器就用此方式编码
} else {
name = java.net.URLEncoder.encode(name,"UTF-8"); //如果是ie浏览器就用此编码
}
}