String fileName = new String(fileName.getBytes(), "ISO8859-1");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
方法2(ie11後失效==)
//判對MSIE 使用URLEncoder.encode() Firefox 使用BCodec.encode()
if (request.getHeader("User-Agent").indexOf("MSIE") != -1) {
response.setHeader("Content-Disposition",
"" + openType + "; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
} else {
try {
response.setHeader("Content-Disposition",
"" + openType + "; filename=\"" + new BCodec().encode(filename, "UTF-8") + "\"");
} catch (EncoderException ex) {
ex.printStackTrace();
}
IE 11 失效是因為他的Engine換Trident
回覆刪除//判斷式:
request.getHeader("User-Agent").contains("Trident")
//編碼同舊IE
FileName = java.net.URLEncoder.encode(FileName, "UTF-8");