struts2谷歌下载文件报错,但是IE能正常下载,有没有解决方法
filename名字为abc.xlsx
public InputStream getDownloadFile() {
try{
InputStream is=ServletActionContext.getServletContext().getResourceAsStream(getUrl());
return is;
} catch(Exception e) {
Log.log(e);
e.printStackTrace();
return null;
}
}
public String downloadFTP() {
try {
setUrl("Ftp/" + getFilename());
System.out.print(filename);
ServletActionContext.getResponse().setHeader("Content-Disposition",
"attachment;fileName=\""+new String(filename.getBytes(),"ISO8859-1")+"\"");
if(getDownloadFile() != null) {
return SUCCESS;
} else {
throw new Exception("下载流为NULL!");
}
} catch(FileNotFoundException e) {
Log.log(e);
e.printStackTrace();
setMsg("提示:下载目标文件不存在!文件路径:" + e.getMessage());
return ERROR;
} catch(Exception e) {
Log.log(e);
e.printStackTrace();
setMsg("提示:" + e.getMessage());
return ERROR;
}
}
上个世纪的技术,还有项目用呢