Example #1
0
 /**
  * 删除附件
  *
  * @return
  * @throws IOException
  */
 public void deleteAtt() throws IOException {
   String id = getRequest().getParameter("attachmentId");
   Attachment attachment = attachmentManager.getById(id);
   String filePath = attachment.getFilePath();
   File file = new File(filePath); // 删除文件
   if (file.exists()) {
     file.delete();
   }
   attachmentManager.removeById(attachment.getId()); // 删除数据库记录
   PrintWriter out = getResponse().getWriter();
   out.print("1");
   out.flush();
   out.close();
 }
Example #2
0
 /** 删除草稿 */
 public String removeDraf() {
   for (int i = 0; i < items.length; i++) {
     Hashtable params = HttpUtils.parseQueryString(items[i]);
     String id = (String) params.get("id");
     List<Attachment> attachments = attachmentManager.findAllBy("refId", id);
     if (attachments != null && !attachments.isEmpty()) {
       getRequest().setAttribute("attachments", attachments);
       for (Attachment attachment : attachments) {
         attachmentManager.delete(attachment);
         String fileName = attachment.getFilePath(); // 得到文件路径
         File file = new File(fileName);
         if (file.exists()) {
           file.delete();
         }
       }
     }
     this.messageManager.removeById(id);
   }
   return "draftAction";
 }
Example #3
0
 /** 上传附件 */
 public void uploadFile(String objId) {
   String fordername = "message"; // 保存文件的文件夹名称
   for (int i = 0; i < file.length; i++) {
     String fullName = FileUtil.creatFullName(this.fileFileName[i], i); // 创建附件全称
     String filePath = FileUtil.createFilePath(fordername, getRequest(), fullName); // 创建附件全路径
     FileUtil.CopyFile(this.file[i].getPath(), filePath); // 上传附件
     // 保存附件信息
     Attachment attachment = new Attachment();
     attachment.setFileName(this.fileFileName[i]); // 文件名称
     attachment.setFilePath(filePath); // 文件路径
     attachment.setExtension(this.fileContentType[i]); // 文件类型
     attachment.setFullName(fullName); // 文件全称
     attachment.setRefId(objId); // 关联ID
     attachment.setAddUserId(getCurrUser().getUserID()); // 创建人ID
     attachment.setAddUserName(getCurrUser().getUserName()); // 创建人姓名
     attachment.setTs(new Date()); // 创建时间
     attachmentManager.save(attachment);
   }
 }