I tried to download xls file using Struts 1, it working in Firefox and downloaded the file with Arabic name but not working in Chrome.
Here is the code :
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");
}
}
when I press the download link it downloads like this :
ØÇáÈÇÊ_ÇáÞÑÂä æÚáæãå.xls