Package org.g4studio.core.mvc.xstruts.upload

Examples of org.g4studio.core.mvc.xstruts.upload.FormFile


   */
  public ActionForward doUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    BaseActionForm cForm = (BaseActionForm) form;
    // 单个文件,如果是多个就cForm.getFile2()....支持最多5个文件
    FormFile myFile = cForm.getFile1();
    // 获取web应用根路径,也可以直接指定服务器任意盘符路径
    String savePath = getServlet().getServletContext().getRealPath("/") + "/upload/";
    // String savePath = "d:/upload/";
    // 检查路径是否存在,如果不存在则创建之
    File file = new File(savePath);
    if (!file.exists()) {
      file.mkdir();
    }
    // 文件按天归档
    savePath = savePath + G4Utils.getCurDate() + "/";
    File file1 = new File(savePath);
    if (!file1.exists()) {
      file1.mkdir();
    }
    // 文件真实文件名
    String fileName = myFile.getFileName();
    // 我们一般会根据某种命名规则对其进行重命名
    // String fileName = ;
    File fileToCreate = new File(savePath, fileName);
    // 检查同名文件是否存在,不存在则将文件流写入文件磁盘系统
    if (!fileToCreate.exists()) {
      FileOutputStream os = new FileOutputStream(fileToCreate);
      os.write(myFile.getFileData());
      os.flush();
      os.close();
    } else {
      // 此路径下已存在同名文件,是否要覆盖或给客户端提示信息由你自己决定
      FileOutputStream os = new FileOutputStream(fileToCreate);
      os.write(myFile.getFileData());
      os.flush();
      os.close();
    }
    // 我们通常还会把这个文件的相关信息持久化到数据库
    Dto inDto = cForm.getParamAsDto(request);
    inDto.put("title", G4Utils.isEmpty(inDto.getAsString("title")) ? fileName : inDto.getAsString("title"));
    inDto.put("filesize", myFile.getFileSize());
    inDto.put("path", savePath + fileName);
    demoService.doUpload(inDto);
    setOkTipMsg("文件上传成功", response);
    return mapping.findForward(null);
  }
View Full Code Here


   * @return
   */
  public ActionForward doUploadBasedFlah(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    BaseActionForm cForm = (BaseActionForm) form;
    FormFile myFile = cForm.getSwfUploadFile();
    // 获取web应用根路径,也可以直接指定服务器任意盘符路径
    String savePath = getServlet().getServletContext().getRealPath("/") + "/upload/";
    // String savePath = "d:/upload/";
    // 检查路径是否存在,如果不存在则创建之
    File file = new File(savePath);
    if (!file.exists()) {
      file.mkdir();
    }
    // 文件按天归档
    savePath = savePath + G4Utils.getCurDate() + "/";
    File file1 = new File(savePath);
    if (!file1.exists()) {
      file1.mkdir();
    }
    // 文件真实文件名
    String fileName = myFile.getFileName();
    // 我们一般会根据某种命名规则对其进行重命名
    // String fileName = ;
    File fileToCreate = new File(savePath, fileName);
    // 检查同名文件是否存在,不存在则将文件流写入文件磁盘系统
    if (!fileToCreate.exists()) {
      FileOutputStream os = new FileOutputStream(fileToCreate);
      os.write(myFile.getFileData());
      os.flush();
      os.close();
    } else {
      // 此路径下已存在同名文件,是否要覆盖或给客户端提示信息由你自己决定
      FileOutputStream os = new FileOutputStream(fileToCreate);
      os.write(myFile.getFileData());
      os.flush();
      os.close();
    }
    // 我们通常还会把这个文件的相关信息持久化到数据库
    Dto inDto = cForm.getParamAsDto(request);
    inDto.put("title", G4Utils.isEmpty(inDto.getAsString("title")) ? fileName : inDto.getAsString("title"));
    inDto.put("filesize", myFile.getFileSize());
    inDto.put("path", savePath + fileName);
    demoService.doUpload(inDto);
    setOkTipMsg("文件上传成功", response);
    return mapping.findForward(null);
  }
View Full Code Here

  public ActionForward doUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    Dto outDto = new BaseDto();
    BaseActionForm cForm = (BaseActionForm) form;
    // 单个文件,如果是多个就cForm.getFile2()....支持最多5个文件
    FormFile myFile = cForm.getFile1();
    // 获取web应用根路径,也可以直接指定服务器任意盘符路径
    String savePath = getServlet().getServletContext().getRealPath("/") + "/upload/demo/";
    //String savePath = "d:/upload/";
    // 检查路径是否存在,如果不存在则创建之
    File file = new File(savePath);
    if (!file.exists()) {
      file.mkdir();
    }
    String type = myFile.getFileName().substring(myFile.getFileName().lastIndexOf("."));
    // 文件真实文件名
    String fileName = getSessionContainer(request).getUserInfo().getUserid();
    fileName = fileName + "_" + G4Utils.getCurrentTime("yyyyMMddhhmmss") + type;
    // 我们一般会根据某种命名规则对其进行重命名
    // String fileName = ;
    File fileToCreate = new File(savePath, fileName);
    if (myFile.getFileSize() > 204800) {
      outDto.put("success", new Boolean(true));
      outDto.put("msg", "文件上传失败,你只能上传小于100KB的图片文件");
      outDto.put("state", "error");
    }else {
      // 检查同名文件是否存在,不存在则将文件流写入文件磁盘系统
      if (!fileToCreate.exists()) {
        FileOutputStream os = new FileOutputStream(fileToCreate);
        os.write(myFile.getFileData());
        os.flush();
        os.close();
      }
      outDto.put("success", new Boolean(true));
      outDto.put("msg", "文件上传成功");
View Full Code Here

   * @throws Exception
   */
  public ActionForward importExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    BaseActionForm actionForm = (BaseActionForm) form;
    FormFile theFile = actionForm.getTheFile();
    String metaData = "xmid,xmmc,xmrj,gg,dw,jx,zfbl,cd,ggsj";
    ExcelReader excelReader = new ExcelReader(metaData, theFile.getInputStream());
    List list = excelReader.read(3, 1);
    super.setSessionAttribute(request, "importExcelList", list);
    setOkTipMsg("导入成功", response);
    return mapping.findForward(null);
  }
View Full Code Here

TOP

Related Classes of org.g4studio.core.mvc.xstruts.upload.FormFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.