Esempio n. 1
0
  /**
   * 下载附件
   *
   * @author 何道军
   * @date 2011-1-7
   * @return String
   */
  public String downloadAttach() {
    try {
      if (attachId == 0) {
        result = "不存在的附件ID,下载失败,请稍后再试!";
        return "success";
      }
      Attach attach = attachService.getAttach(attachId);
      if (attach == null) {
        write(
            "<html><head><title>出错了</title></head><body>"
                + "<div style=\"text-align: center;margin-top: 100px;\">您下载的附件不存在,请检查数据完整性!</div>"
                + "</body></html>");
        return null;
      }
      fileStream = new FileInputStream(attach.getAttachUrl());
      uploadAttachFileName = attach.getAttachName();

      attach.setDownloadTime(attach.getDownloadTime() + 1);
      attachService.updateAttach(attach);

    } catch (FileNotFoundException e) {
      write(
          "<html><head><title>出错了</title></head><body>"
              + "<div style=\"text-align: center;margin-top: 100px;\">您下载的文件不存在,可能已经从服务器上删除!</div>"
              + "</body></html>");
      return null;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return "success";
  }
Esempio n. 2
0
 /**
  * 批量删除附件 @Title deleteUser
  *
  * @author hedaojun
  * @date 2015-2-15
  * @return String
  */
 public String deleteAttachs() {
   try {
     String attachIds = this.getRequest().getParameter("attachIds");
     for (String attachId : attachIds.split(",")) {
       Attach attach = attachService.getAttach(Integer.parseInt(attachId));
       // 删除数据库记录
       attachService.removeAttach(attach.getAttachId());
       // 从服务器硬盘删除文件
       FileUtil.delFile(attach.getAttachUrl());
     }
     JsonUtil.outJson("{success:true,msg:'删除成功!'}");
   } catch (Exception e) {
     JsonUtil.outJson("{success:false,msg:'删除失败!'}");
     this.excepAndLogHandle(UserAction.class, "批量删除附件", e, false);
   }
   return null;
 }
Esempio n. 3
0
  /**
   * 删除附件
   *
   * @author 何道军
   * @date 2011-1-7
   * @return String
   */
  public String deleteAttach() {
    try {
      if (attachId == 0) {
        result = "不存在的附件ID,删除失败,请稍后再试!";
        return "success";
      }
      Attach attach = attachService.getAttach(attachId);
      // 删除数据库记录
      attachService.removeAttach(attach.getAttachId());
      // 从服务器硬盘删除文件
      FileUtil.delFile(attach.getAttachUrl());

      result = "Y";
    } catch (Exception e) {
      e.printStackTrace();
      result = "删除失败,请稍后再试!";
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("result", result);
    JsonUtil.outJson(resultMap);
    return null;
  }