返回结果设置
@Result(name = "downloadDrive", type = "stream", params = { "contentType", "application/octet-stream;",
"contentDisposition", "attachment;filename=${fileName}", "inputName", "fileStream", "bufferSize","1024"})
后台control方法
//下载文件
public String download(){
try {
//获取存在文件的路径
String realPath = ServletActionContext.getServletContext().getRealPath("/app");
File file = new File(new File(realPath), "zwzx.ipa");
String str="政务咨询";
if(appNo.equals("1")){
file = new File(new File(realPath), "zwzx.ipa");
fileName = new String(str.getBytes("GBK"),"iso-8859-1")+".ipa";
}else if(appNo.equals("2")){
file = new File(new File(realPath), "zwzx.apk");
fileName = new String(str.getBytes("GBK"),"iso-8859-1")+".apk";
}
fileStream = new FileInputStream(file);
} catch(Exception e) {
logger.error("下载过程中出错", e);
}finally{
/* try {
fileStream.close();
} catch (Exception e) {
e.printStackTrace();
}*/
}
return "downloadDrive";
}