xml
<action name="L_download" class="cnydlanFileAction" method="download"> <result name="success" type="stream"> <param name="contentType">application/octet-stream;charset=ISO8859-1</param> <param name="inputName">inputStream</param> <param name="contentDisposition">attachment;filename="${downloadFileName}"</param> <param name="bufferSize">4096</param> </result> </action>
action
/** * 处理中文下载名 * @throws Exception * */ public String getDownloadFileName() throws Exception { String named = new String(name.getBytes(), "ISO8859-1"); if (zipName1.length() > 0){ named = new String(zipName1.getBytes(), "ISO8859-1"); } return named; } /** * 获得文件下载流 */ public InputStream getInputStream() throws Exception { HttpServletRequest actionRequest = ServletActionContext.getRequest(); Map session = (Map)ActionContext.getContext().getSession(); String[] tt = getPaths(); if (tt != null && tt.length > 0){ this.paths = URLDecoder.decode(tt[0], "UTF-8").split(","); compressionFilesToTemparayPackage(); String path1 = ""; path1 = getTempPath() + zipName1; deleteZipFiles(); InputStream in = new FileInputStream(path1); return in; } else { logger.info("IP: " + actionRequest.getRemoteAddr() + " 开始下载文件" + name + " time: " + getTime()); String path1 = ""; String temproot = path; String para1 = getRoot(); if (temproot.equals("*") == false){ path1 = getRoot() + temproot + "\\" + name; para1 = getRoot() + temproot; } else { path1 = getRoot() + "\\" + name;} para1 = path1; //getFullPathSetDataBase(para1, name); markDownLoadInfo(para1, name); InputStream in = new FileInputStream(path1); logger.info("IP: " + actionRequest.getRemoteAddr() + " 结束下载文件" + MyUtils.URLDecoder(name) + " time: " + getTime()); return in; } } /** * 下载文件 */ public String download() { return SUCCESS; }