fileDownLoad


下载
//downloadFileProcess action name | fileFileName 对应downloadFileProcess() 中 fileFileName
--------------------------------------------------------------------------------------------------------------

method="downloadFileProcess">

inputStream
attachment;filename="${#request.fileDownloadName}"
2048


//${#request.fileDownloadName} 对应 downloadFileProcess() 中 getRequest().put("fileDownloadName", fileDownloadName);
getRequest()是jsp内置对象 可以用ServletContext 拿到
------------------------------------------------------------------------------------------------------------
public String downloadFileProcess() throws Exception {
fileFileName = new String(fileFileName.getBytes("ISO-8859-1"), "UTF-8");// 前台传过来的文件名转码
String filePath = fileDirPath + File.separator + fileFileName; //产生文件的实际路径
File downloadFile = new File(filePath); //实例化文件
log.debug("filePath :" + filePath);
if (downloadFile.exists()) {
log.debug("-----downloadFileProcess success 1-----");
if (downloadFile.isFile()) {
inputStream = new BufferedInputStream(new FileInputStream(
downloadFile));//对应action stream

String fileDownloadName = new String(downloadFile.getName().getBytes("UTF-8"),"ISO-8859-1");//浏览器只能识别ISO-8859-1,再转回去
https://www.360docs.net/doc/ad7165960.html,("downloadFile.getName():" + downloadFile.getName());
https://www.360docs.net/doc/ad7165960.html,("fileDownloadName:" + fileDownloadName);
getRequest().put("fileDownloadName", fileDownloadName);
try{
fileService.UpDateDownloadNum(downloadFile.getName());
}catch(Exception e){
log.error(" UpDateDownloadNum Exception" , e);
}
https://www.360docs.net/doc/ad7165960.html,("-----downloadFileProcess success-----");
return SUCCESS;

}
} else {
log.debug("-----downloadFileProcess error-----");
return ERROR;
}
log.debug("-----downloadFileProcess end-----");
return SUCCESS;
}

相关主题
相关文档
最新文档