Beispiel #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();
 }
Beispiel #2
0
 /**
  * 下载附件
  *
  * @return
  * @throws Exception
  */
 public void download() throws Exception {
   String attachId = getRequest().getParameter("attachId");
   String fileName = attachmentManager.getById(attachId).getFileName();
   String filePath = attachmentManager.getById(attachId).getFilePath();
   // 文件路径
   // String folderPath = getRequest().getSession().getServletContext().getRealPath("/upload")
   // +File.separator+ "inform" ;
   FileUtil.downLoad(filePath, fileName, getResponse(), false); // false为下载,true为在线打开,此处是下载所以是false
 }
Beispiel #3
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";
 }
Beispiel #4
0
 /** 查看 */
 public String view() {
   List<Attachment> attachments = attachmentManager.findAllBy("refId", this.message.getId());
   getRequest().setAttribute("attachments", attachments);
   String rs = this.message.getReceiver();
   String username = this.getCurrUser().getUserName();
   if (rs.equals(username)) {
     this.message.setState("1");
     if (message.getChackTime() == null) {
       this.message.setChackTime(new Date());
     }
     this.messageManager.update(this.message);
   }
   return VIEW_JSP;
 }
Beispiel #5
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);
   }
 }
Beispiel #6
0
 /** 修改 */
 public String editdraft() {
   List<Attachment> attachments = attachmentManager.findAllBy("refId", this.message.getId());
   getRequest().setAttribute("attachments", attachments);
   return EDIT_JSP;
 }