zoukankan      html  css  js  c++  java
  • struts2文件上传

     1 //文件
     2     private File file;
     3     //文件名称
     4     private String fileFileName;
     5     private String fileContentType;
     6 
     7 
     8 /*
     9      * 添加方法
    10      */
    11     public String districtSave(){
    12         try {
    13             if(file!=null){
    14                 String tem_path = this.contextPvd.getAppRealPath(Util.FILE_FOLDER);
    15                 String file_name = UploadFile.copy(file, tem_path, this.getFileFileName());    
    16                 String path = Util.FILE_FOLDER+File.separator+file_name;//原始图片保存路径
    17                 districtTest.setUpload(path);
    18                 
    19                 /*//上传文件路径
    20                 String path = Util.FILE_FOLDER+"/"+Util.DOWN+"/";
    21                 //文件名称重命名
    22                 String file_name = UtilMethod.generateFileName(myFileFileName);
    23                 File uploadFile = new File(ServletActionContext.getServletContext().getRealPath(path), file_name);
    24                 if(!uploadFile.exists()){
    25                     FileUtils.copyFile(myFile, uploadFile);
    26                 }
    27                 districtTest.setUpload(path+file_name);*/
    28             }
    29             districtTest.setCreateTime(new Date());
    30             districtTest.setUpdateTime(new Date());
    31             districtTest.setIsDele(0);
    32             this.utilService.save(districtTest);
    33             Loggers.logToDB("执行了添加区县操作", contextPvd.getSessionId(Util.SESSION_SYS_USER), Util.CREATE);
    34             return districtList();
    35         } catch (Exception e) {
    36             // TODO: handle exception
    37             Loggers.error("----DistrictTestAction的districtSave方法错误"+e.getMessage());
    38             e.printStackTrace();
    39         }
    40         return ERROR;
    41     }
    View Code
  • 相关阅读:
    P2949 [USACO09OPEN]工作调度Work Scheduling
    P1279 字串距离 (动态规划)
    P2634 [国家集训队]聪聪可可
    点分治模板
    网站收集
    P1131 [ZJOI2007]时态同步
    P1446 [HNOI2008]Cards
    P1437 [HNOI2004]敲砖块
    蓝桥杯-k倍区间
    atom / vscode (配置c++环境流程)
  • 原文地址:https://www.cnblogs.com/yang1018/p/7169984.html
Copyright © 2011-2022 走看看