首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

将以前的自已写的东西代走,以备以后用——文件下传上载

2012-09-01 
将以前的自已写的东西代走,以备以后用——文件上传下载public class ESImgUploadUtilextends FrameworkObjec

将以前的自已写的东西代走,以备以后用——文件上传下载

public class ESImgUploadUtil        extends FrameworkObject {/* * 文件上传功能 * @author LYJ * @date 2010/09/05 */private static final long serialVersionUID = 1L;private long sysMaxSize = (5024*1024);    private List fileTypes = Arrays.asList(new String[]{".GIF",".JPG",".JPEG"});    public static final String FILE_SEPARATOR = "file.separator";    public static final String DEFAULT_FILE_UPLOAD_PATH = "repository";    private String msg = "";    private ESImgUploadModel eSImgUploadModel = new ESImgUploadModel();    private EsRepairFacade facade = new EsRepairFacade();    private List upLoadFileList = new ArrayList();    public String imgFileUpLoad(HttpServletRequest request,String curId,String itemId){    DiskFileUpload diskFileUpload = new DiskFileUpload();    //设置文件流编码    if(request.getCharacterEncoding().equals("")||request.getCharacterEncoding()==null){    diskFileUpload.setHeaderEncoding("UTF_8");    }else{    diskFileUpload.setHeaderEncoding(request.getCharacterEncoding());    }    //获得用户当前项目路径    String dir = getProperty(USER_DIR);    String tempDir = dir+"\\imgTemp";    String upLoadDir = dir+"\\imgUpLoad";    File temp_Dir = new File(tempDir);    File upLoad_Dir = new File(upLoadDir);    eSImgUploadModel.setSizeMax(sysMaxSize);    //检查目是否存在,若不存在  刚创建此目录    try {    if(!temp_Dir.exists()){    //创建目录        temp_Dir.mkdir();        }    if(!upLoad_Dir.exists()){    upLoad_Dir.mkdir();    }} catch (Exception e) {msg += e.getMessage();}        //设置上传文件大小    diskFileUpload.setSizeMax(sysMaxSize);    //设置充许存在在内存缓存中的大小    diskFileUpload.setSizeThreshold(4096);    //设置上传文件的大小一但超过setSizeThreshold大小时,即存到RepositoryPath的物理路径下    diskFileUpload.setRepositoryPath(DEFAULT_FILE_UPLOAD_PATH + System.getProperty(FILE_SEPARATOR));     //得到上传信息    try { List list = diskFileUpload.parseRequest(request); Iterator iter = list.iterator();    while(iter.hasNext()){    FileItem item = (FileItem)iter.next();    if(!item.isFormField()){   eSImgUploadModel.setItemId(itemId);    String fileName = item.getName();    eSImgUploadModel.setFilePath(upLoadDir);    fileName = fileName.substring(fileName.lastIndexOf("\")+1);//获得文件名,且不包括路路径    eSImgUploadModel.setFileName(fileName);    long fileSize = item.getSize();    eSImgUploadModel.setFileSize(fileSize);    //获取文件类型    String fileType = fileName.substring(fileName.lastIndexOf("."));    eSImgUploadModel.setFileType(fileType);    fileType = fileType.toUpperCase();    if(fileTypes.contains(fileType)){            if(fileName != null && !fileName.equals("") && fileSize!= 0){            //开始操作文件的上读入            item.write(new File(upLoadDir,fileName));            upLoadFileList.add(eSImgUploadModel);           facade.upLoadPhoto(eSImgUploadModel,curId);            }    }else{   msg += "SERVICE.MESSAGE_FILE_TYPE";    }    }    }} catch (FileUploadException e) {msg += e.getMessage();} catch (Exception e) {msg += e.getMessage();}    return msg;        }        public String getMessage(){    return  this.msg;    }    public List upLoadFileList(){    if(this.upLoadFileList.size()< 1){    return null;    }else{    return this.upLoadFileList;    }    }   }

?

热点排行