标签:查看 href put gets 部分 ref back res size
public class FileDownLoadAction extends ActionSupport{ private String filename;//下载文件的名称 @Override public String execute() throws Exception { return SUCCESS; } //下载源 public InputStream getInputStream() throws IOException{ String path =ServletActionContext.getServletContext().getRealPath(filename);//获取文件路径 //System.out.println("path="+path); File file = new File(path); return FileUtils.openInputStream(file); } //下载文件名 public String getDownloadFileName() throws Exception{ String downloadFileName=""; String []filenames=filename.split("/"); //System.out.println(filenames[filenames.length-1]); downloadFileName=URLEncoder.encode(filenames[filenames.length-1], "UTF-8");//解决下载中文命名文件乱码问题 return downloadFileName; } ///////////////////////////////////////////字段封装////////////// public String getFilename() { return filename; } public void setFilename(String filename) { this.filename = filename; } }
<action name="download" class="com.zzuli.student.action.FileDownLoadAction"> <!--以流的方式返回 --> <result name="success" type="stream"> <!--文件流 --> <param name="contentType">application/octet-stream</param> <!--下载源 --> <param name="inputName">InputStream</param> <!--以附件方式下载 downloadFileName相应Action类getDownloadFileName() --> <param name="contentDisposition">attachment;filename="${downloadFileName}"</param> <!--缓冲流大小 --> <param name="bufferSize">8192</param> </result>
<td> <a href="download.action?filename=${documentUrl}">点击下载</a> </td>
标签:查看 href put gets 部分 ref back res size
原文地址:http://www.cnblogs.com/cxchanpin/p/7073250.html