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
  • 相关阅读:
    spring中@Autowired与 @Resource区别
    linux系统镜像iso文件下载
    log4j.properties配置说明学习网址
    maven常用命令
    mysql优化
    mybatis与hibernate区别
    struts2与SpringMVC区别
    java同步锁实现方法
    java多线程的四种实现方式
    java单例模式几种实现方式
  • 原文地址:https://www.cnblogs.com/yang1018/p/7169984.html
Copyright © 2011-2022 走看看