struts2整合uploadify插件实现批量上传,上传成功后跳转并传递参数

<link href="static/uploadify/uploadify.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="static/uploadify/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="static/uploadify/swfobject.js"></script> <script type="text/javascript" src="static/uploadify/jquery.uploadify.v2.1.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ 'uploader' : 'static/uploadify/uploadify.swf', //是组件自带的flash,用于打开选取本地文件的按钮 'script' : 'upload.action',//处理上传的路径,这里使用Struts2是XXX.action 'scriptData' :{'catId':$('#catId').val()}, 'cancelImg' : 'static/uploadify/cancel.png',//取消上传文件的按钮图片,就是个叉叉 'folder' : 'uploads',//上传文件的目录 'fileDataName' : 'uploadify',//和input的name属性值保持一致就好,Struts2就能处理了 'queueID' : 'fileQueue', 'auto' : false,//是否选取文件后自动上传 'multi' : true,//是否支持多文件上传 'simUploadLimit' : 1,//每次最大上传文件数 'queueSizeLimit' : 50, 'removeCompleted' : true, 'buttonText' : 'BORWSE',//按钮上的文字 'displayData' : 'percentage',//有speed和percentage两种,一个显示速度,一个显示完成百分比 'fileDesc' : '支持格式:jpg/gif/jpeg/png/bmp.', //如果配置了以下的'fileExt'属性,那么这个属性是必须的 'fileExt' : '*.jpg;*.gif;*.jpeg;*.png;*.bmp',//允许的格式 'onComplete' : function(event, queueID, fileObj, response, data) { //$("#result").html(response);//显示上传成功结果 //setInterval("showResult()", 2000);//两秒后删除显示的上传成功结果 window.location.href="<%=basePath%>photoManage/uploadPhoto.action?catId="+$('#catId').val();//上传成功后跳转,并传递参数 } }); }); //function showResult() {//删除显示的上传成功结果 // $("#result").html(""); //} function uploadFile() {//上传文件 jQuery('#uploadify').uploadifyUpload(); } function clearFile() {//清空所有上传队列 jQuery('#uploadify').uploadifyClearQueue(); } </script> <input type="file" name="uploadify" id="uploadify"/> <s:hidden name="catId"></s:hidden> //上传成功后要传递的参数值 <div> <div id="fileQueue"></div> </div> <input type="button" οnclick="uploadFile()" value="开始上传"> <input type="button" οnclick="clearFile()" value="取消所有上传">

接受上传处理的Action

private File uploadify; private String uploadifyFileName; public String upload()throws Exception{ String extName = ""; PhotoService photoService = ServiceLocator.getPhotoService(); String saveRealFilePath = ServletActionContext.getServletContext().getRealPath("/upload"); File fileDir = new File(saveRealFilePath); if (!fileDir.exists()) { fileDir.mkdirs(); } File savefile; if(uploadifyFileName.lastIndexOf(".")>=0){ extName = uploadifyFileName.substring(uploadifyFileName.lastIndexOf(".")); } String nowTime = ""+new Date().getTime(); savefile = new File(saveRealFilePath + "/" + nowTime + extName); try { Photo photo = new Photo(); photo.setCatId(Integer.parseInt(catId)); photo.setPhotoName(nowTime + extName); boolean result = photoService.insertPhoto(photo); } catch (Exception e) { e.printStackTrace(); } FileUtils.copyFile(uploadify,savefile); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("utf-8"); response.getWriter().print(uploadifyFileName+"上传成功"); return null; } public File getUploadify() { return uploadify; } public void setUploadify(File uploadify) { this.uploadify = uploadify; } public String getUploadifyFileName() { return uploadifyFileName; } public void setUploadifyFileName(String uploadifyFileName) { this.uploadifyFileName = uploadifyFileName; }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值