工作记录:文章详情页的附件下载,基于struts2的文件下载
2014-10-07 00:00
531 查看
摘要: 文章详情页的附件下载,基于struts2的文件下载
系统架构是 struts2 ibatis spring,使用jquery easy ui 进行数据的展示等。
本例是 此系统下的文件下载;
系统架构是 struts2 ibatis spring,使用jquery easy ui 进行数据的展示等。
本例是 此系统下的文件下载;
1. 首先jsp页面上遍历出要下载的文件:(存储在request域中的List<Map>) <c:forEach var="dList" items="${atttachmentLsit}" varStatus="sta" > ?<a href="###" onclick="toDownLoad('${dList.VCHR_ID}');"> ${fn:substring(dList.VCHR_ORIGINNAME, 0, 20)}<c:if test="${fn:length(dList.VCHR_ORIGINNAME)>20}">...</c:if></a> <br> </c:forEach> 2. 点击文件,触发toDownLoad(...)方法:此js方法具体为; function toDownLoad(vchr_id){//附件的主键id url="questionQueryAction!toDownLoad.dhtml?vchr_id="+vchr_id; window.location.href=url; } 3. action中的toDownLoad()以及其他需要的内容如下: private String inputPath = "";// 下载文件路径+名称 private String filename = "";// 所要下载文件的名称 /** * 和配置文件对应,必须加 * @return * @throws Exception */ public InputStream getTargetFile() throws Exception { return new java.io.FileInputStream(inputPath); } public String getInputPath() { return inputPath; } public void setInputPath(String inputPath) { this.inputPath = inputPath; } /** * 转码,必须加 * @return */ public String getFilename() { try { filename = new String(filename.getBytes("GBK"), "ISO8859-1"); //filename = new String(filename.getBytes(), "ISO8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return filename; } public void setFilename(String filename) { this.filename = filename; } /** * 执行文件下载.9/29 mamy */ public String toDownLoad(){ String vchr_id = super.getRequestParameter("vchr_id"); Map map = (Map)dealSimpleService.getObject("questionQt.queryOneAttachment", vchr_id); String fileName = map.get("VCHR_ORIGINNAME").toString(); String fileNameString = map.get("VCHR_STORAGENAME").toString(); String filePath = ResourceMessage.newInstance().getValue("uploadfile.zmhd"); this.setFilename(fileName); this.setInputPath(filePath + File.separator+"zmhd" + File.separator + fileNameString); return "download"; } 4. download在struts。xml中的配置为: <result name="download" type="stream" > <param name="contentType">application/octet-stream;charset=ISO8859-1</param> <param name="inputName">targetFile</param> <param name="contentDisposition">attachment;filename="${filename}"</param> <param name="bufferSize">4096</param> </result>
相关文章推荐
- 基于struts2的文件上传与下载
- WEB文件上传下载过程简介(基于Struts2)
- 基于Struts2文件下载
- 基于Struts2的单文件下载
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程
- 基于struts2--实现文件上传下载
- struts2学习笔记(六)文件上传与下载(下)基于Struts2的文件上传与下载
- struts2基于注解的文件下载
- 基于 Struts2 的文件下载
- 基于Struts2的单文件下载
- 【SSH2(实用文章)】--Struts2文件上传和下载的例子
- 基于struts2--实现文件上传下载
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程 (摘自:http://www.blogjava.net/xcp/archive/2009/10/30/downloadlist.html)
- 基于struts2的文件上传下载
- struts2文件上传下载及乱码问题解决
- 解决Struts2在IE7下文件下载问题
- Struts2控制文件下载
- struts2文件下载
- 基于asp.net的文件上传和下载