首页 JAVA开发-上传下载附件

JAVA开发-上传下载附件

举报
开通vip

JAVA开发-上传下载附件LEAP框架-选择树控件使用指南 LEAP框架开发使用指南-上传下载附件 在LEAP平台下进行项目开发,在上传下载附件时以控件的形式开发使用,现介绍如下: 1、引入上传下载附件所需CSS、JS 2、JSP页面上传下载附件控件加载 上传下载JS脚本 var uploads = []; window.onload = function(){ var u = rims.upload.newSWFUpload({ progressTarget : "fsUploadProgress1", cancelButto...

JAVA开发-上传下载附件
LEAP框架-选择树控件使用指南 LEAP框架开发使用指南-上传下载附件 在LEAP平台下进行项目开发,在上传下载附件时以控件的形式开发使用,现介绍如下: 1、引入上传下载附件所需CSS、JS 2、JSP页面上传下载附件控件加载 附件显示iframe控制 上传div区域
下载div区域
  3、上传附件获取与保存JAVA类 //保存附件 KnowledgedocAttachmentUtil.saveAttachments(this.getRequest(), knowledgedoc.getId(), "KNOWLEDGEDOC", this.attachmentMap); KnowledgedocAttachmentUtil类中保存附件相关方法saveAttachments: /** * 保存附件 * @param knowledgedocId 知识ID * @param knowledgedocphase 知识附件标识 * @param Map>知识附件ListMap */ public static void saveAttachments(HttpServletRequest request, int knowledgedocId, String knowledgedocphase, Map> attachmentMap){ String username = UserContextUtil.getCurrentUser().getUsername(); String uploadTempDir = Configuration.getUploadTempDir(); List tempfiles = new ArrayList(); KnowledgedocService knowledgedocService = (KnowledgedocService) SpringFactory.getInstance().getBean("knowledgedocService"); Map attachmap =ObjectUtil.convertListToMap(knowledgedocService. findAttachmentsByKnowledgedocId(knowledgedocId)); for(Iterator it = attachmentMap.keySet().iterator(); it.hasNext();){ String k = (String)it.next(); List attachments = (List)attachmentMap.get(k); for( Map attach : attachments){ String fileId = (String)attach.get("fid"); String[] items = fileId.split("\\|"); int id = Integer.parseInt(items[0]); if ( id == 0 ){ String filename = items[1]; int p = filename.lastIndexOf('.'); String suffix = p < 0 ? null : filename.substring(p+1); // 新增附件 byte[] content = null; try{ ByteArrayOutputStream fout = new ByteArrayOutputStream(); InputStream fin = IOUtil.readFileFromDir (uploadTempDir, items[2]); IOUtils.copy(fin, fout); content = fout.toByteArray(); tempfiles.add(items[2]); }catch(Exception ex){ log.warn("读取上传文件失败![" + fileId + "]", ex); } if ( content != null ){ KnowledgedocAttachment item = new KnowledgedocAttachment(); item.setContentSize(content.length); item.setContentType(suffix); item.setCreateUsername(username); item.setName(filename); item.setKnowledgedocId(knowledgedocId); item.setType(knowledgedocphase); item.setUpdateUsername(username); knowledgedocService.insertAttachment(item, content); } } else{ attachmap.remove(new Integer(id)); } } // 清除多余附件 for(Iterator ita = attachmap.values().iterator(); ita.hasNext();){ KnowledgedocAttachment item = (KnowledgedocAttachment)ita.next(); knowledgedocService.deleteAttachmentById(item.getId()); } // 清除上传的临时文件 for(String file : tempfiles){ IOUtil.deleteFile(uploadTempDir, file); } } } } 4、附件显示与下载 页面附件加载下载JS 页面附件加载显示区域 附件 <%=++attachmentnum%> //下载附件页面请求 ${item.fileItems[1]} 后台JAVA处理类方法 // 加载已有附件类方法 this.attachmentMap = KnowledgedocAttachmentUtil.prepareKnowledgedocAttachments(this.knowledgedocId); List _attachments = knowledgedocService.findAttachmentsByKnowledgedocId(this.knowledgedocId); request.setAttribute("uploadfiles",_attachments); // 下载附件类KnowledgedocAttachmentDownloadAction public class KnowledgedocAttachmentDownloadAction extends DispatchAction{ private int attachmentId = 0; public int getAttachmentId() { return attachmentId; } public void setAttachmentId(int attachmentId) { this.attachmentId = attachmentId; } public String download()throws IOException,IllegalStateException{ KnowledgedocService knowledgedocService = (KnowledgedocService) SpringFactory.getInstance().getBean("knowledgedocService"); KnowledgedocAttachment attach = knowledgedocService. findAttachmentById(this.attachmentId); if ( attach != null ){ byte[] content = knowledgedocService. findAttachmentContentById(this.attachmentId); HttpUtil.download(this.getResponse(), attach.getName(), new ByteArrayInputStream(content)); } return null; } }
本文档为【JAVA开发-上传下载附件】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_447231
暂无简介~
格式:doc
大小:68KB
软件:Word
页数:5
分类:互联网
上传时间:2011-04-12
浏览量:51