我尝试使用 Struts 1 下载 xls 文件,它在 Firefox 中运行,并下载了阿拉伯名称的文件,但在 Chrome 中无法运行。
这是代码:
public void download(CommandContext context, byte[] data, String filename) {
String CONTENT_TYPE = "application/unknown";
HttpServletResponse response = (HttpServletResponse) context
.get(context.RESPONSE_KEY);
try {
response.setContentType(CONTENT_TYPE);
response.setContentLength(data.length);
String str = "attachment; filename=\""
+ new String(filename.getBytes("cp1256"), "cp1252") + "\"";
response.setHeader("Content-Disposition", str);
response.setHeader("Expires", "0");
response.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
OutputStream outputStream = response.getOutputStream();
outputStream.write(data);
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
getLogger(this.getClass().getName()).error(
"Can't download file of newly generated card numbers");
}
}
当我按下下载链接时,它会像这样下载:
ØÇáÈÇÊ_ÇáÞÑÂä æÚáæãå.xls