Beispiel #1
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 #2
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();
 }