国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

uploadify文件上傳的使用

2019-11-14 23:48:39
字體:
來源:轉載
供稿:網友
uploadify文件上傳的使用

1.jsp代碼

 1     appname=$("#appname").val(); 2         $("#uploadify").uploadify({ 3             'swf' : '<%=basePath%>/Backstage/Style/jQuery-uploadify/uploadify.swf', 4             // 'scr
1     <input type="file" name="uploadify" id="uploadify" />2                 <input id="appname" type="text" value="<s:property value="version.appName"/>" name="version.appName" size="30"   maxlength="32"  data-options="required:true,missingMessage:'請輸入版本號'" class="easyui-validatebox" /><font color="red">&nbsp;*</font>

2.action和service

 1     public void addVersion() { 2         String appname= getRequest().getParameter("appname"); 3         UploadImg upload = new UploadImg(); 4         try { 5             /** 商品基本屬性 **/ 6             version.setId(Constants.getUUID()); 7             version.setCreateTime(Constants.getSimpleDateFormat3()); 8  9             /** 將緩存中的圖片放入版本目錄中 **/10             List<String> files = (List<String>) getsession().getAttribute("files");11             String filesext=(String) getSession().getAttribute("fileExt");12             String updateUrl=(String) getSession().getAttribute("fileName1");13             if (files != null) {14                 SimpleDateFormat yearFormat = new SimpleDateFormat("yyyyMMdd");15                 String folderName = Constants.versionFileSavePath + "/" + yearFormat.format(new Date()) ;16                 String newFileName=appname+"."+filesext;17                 for (int i = 0; i < files.size(); i++) {18                     upload.moveAndSaveFile(getRequest(), "/Upload/temp" +files.get(i), "/Upload/"+folderName,newFileName);19                 }20                 version.setUpdateUrl(updateUrl);21 //                commodityInfo.setImageDir("/Upload/" + folderName);22             }23             getSession().removeAttribute("files");24             getSession().removeAttribute("fileName1");25             this.wfAppVersionService.addObject(version);26             String json = JSON.toJSONString(version);27             json = json.replace("}", ",/"tips/":/"新增版本信息成功/"}");28             getResponse().setContentType("text/html;charset=utf-8");29             getResponse().getWriter().println(json);30         } catch (Exception ex) {31             ex.printStackTrace();32             try {33                 getResponse().setStatus(555);34                 getResponse().getWriter().println("新增失敗");35                 Logger.getLogger(AppVersionAction.class).info("版本控制執行新增操作異常");36             } catch (IOException e) {37                 e.printStackTrace();38             }39         }40     }
 1     public void copyAndUpateFile(HttpServletRequest request,String oldPath, String newPath, String newName) { 2         try { 3             int bytesum = 0; 4             int byteread = 0; 5             System.out.println("@@newPath:  "+newPath); 6             File oldfile = new File(request.getRealPath("/")+oldPath); 7             if (oldfile.exists()) { // 文件存在時 8                 //查看傳入的目錄是否存在 如果不存在就創建 9                 if (newPath.split("/").length > 0) {10                     String[] paths = newPath.split("/");11                     String path = request.getRealPath("/") ;12                     for (int i = 0; i < paths.length; i++) {13                         path += paths[i] + "/";14                         File saveDirFile = new File(path);15                         if (!saveDirFile.exists()) {16                             saveDirFile.mkdirs();17                         }18                     }19                 }20                 File file=new File(request.getRealPath("/")+newPath+"/"+"cbt_"+newName);21                 file.createNewFile();22                 InputStream inStream = new FileInputStream(request.getRealPath("/")+oldPath); // 讀入原文件23                 FileOutputStream fs = new FileOutputStream(request.getRealPath("/")+newPath+"/"+"cbt_"+newName);24                 byte[] buffer = new byte[1444];25                 while ((byteread = inStream.read(buffer)) != -1) {26                     bytesum += byteread; // 字節數 文件大小 27                     fs.write(buffer, 0, byteread);28                 }29                 inStream.close();30             }31         } catch (Exception e) {32             System.out.println("復制單個文件操作出錯");33             e.printStackTrace();34 35         }36     }37     38     /**39      * 將臨時文件tmp移動并改變格式40       * @Title:  UploadImg41       * @param:  @param request42       * @param:  @param oldPath43       * @param:  @param newPath44       * @param:  @param newName45       * @return:       46       * @throws:47       * @Description: TODO48      */49     public void moveAndSaveFile(HttpServletRequest request,String oldPath, String newPath,String newName) {50         copyAndUpateFile(request,oldPath, newPath,newName);51         String fileExt = oldPath.substring(oldPath.lastIndexOf(".") + 1).toLowerCase();52         System.out.println("oldPath:      "+oldPath+"###NewPath:  "+newPath+" fileExt:   "+fileExt);53         delFile(request,oldPath);54 55     }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 常山县| 云浮市| 融水| 镇坪县| 桓仁| 沾益县| 塔城市| 巍山| 沾益县| 榕江县| 郴州市| 新郑市| 赤壁市| 尼勒克县| 玉门市| 都匀市| 常德市| 甘肃省| 根河市| 子长县| 永修县| 扶沟县| 宣威市| 鞍山市| 奉节县| 偃师市| 东阿县| 原阳县| 濮阳县| 迁安市| 汉沽区| 镇雄县| 江阴市| 汶川县| 盱眙县| 青阳县| 长汀县| 防城港市| 伊宁县| 江北区| 湖北省|