如题,火狐浏览器对编码格式有特殊要求
做如下配置:
OutputStream outstream = null;
try {
resp.setContentType("application/octet-stream;charset=UTF-8");
String agent = req.getHeader("USER-AGENT");
outstream= resp.getOutputStream();
resp.reset();
if(fileName.contains(",")){
fileName = fileName.replaceAll(",", "_");
}
//判断浏览器类型
if(agent != null && agent.toLowerCase().indexOf("firefox") > 0)
{
fileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(fileName.getBytes("UTF-8")))) + "?=";
}
else
{
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
}
resp.setHeader("Content-Disposition","attachment;filename="+fileName);
resp.setHeader("Set-Cookie", "fileDownload=true; path=/");//设置回调成功
outstream.write(b);
outstream.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(outstream!=null){
outstream.close();
}
}