欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
struts上傳和下載2個(gè)action
上傳和下載2個(gè)action
[原創(chuàng ) 2006-11-13 14:43:17 ] 發(fā)表者: slingnong  

上傳:
public ActionForward upload(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  String path = getServlet().getServletContext().getRealPath("/");
  if (form == null) {
   return mapping.findForward("success");
  }
  FileUploadForm fuf = (FileUploadForm) form;
  FormFile file = fuf.getFile();
  try {
   if (file == null) {
    return mapping.findForward("success");
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  String fname = file.getFileName();
  int t = 0;
  for (int i = 0; i < fname.length(); i++) {
   if (fname.charAt(i) == ‘.‘) {
    t = i;
   }
  }
  /**
   * 文件名
   */
  String filename = null;
  if (t > 0) {
   filename = fname.substring(0, t);
  }
  ServletContext servletContext = servlet.getServletContext();
  ApplicationContext ctx = WebApplicationContextUtils
    .getRequiredWebApplicationContext(servletContext);
  LawCaseDAO lawCaseDAO = (LawCaseDAO) ctx.getBean("lawCaseDAO");

  Tajjbxx lawcase = lawCaseDAO.view(fuf.getFid());
  String urlFileName = lawcase.getBaAjbh() + "_" + fuf.getLx();
  urlFileName += fname.substring(t);
  /**
   * 保存文件路徑
   */
  String filepath = "/pages/lawcase/wenshu/" + urlFileName;

  /**
   * 先生成文件保存的路徑
   */
  if (!(new File(path + "/pages/lawcase/wenshu/")).exists()) {
   (new File(path + "/pages/lawcase/wenshu/")).mkdirs();
  }
  /**
   * 將上傳的文書(shū)信息保存到數據庫中
   */

  Tajws wenshu = new Tajws();

  /**
   * 設置文書(shū)所對應的案件id
   */
  wenshu.setAjseqid(new Long(fuf.getFid()));
  /**
   * 設置文書(shū)的名稱(chēng)
   */
  wenshu.setWsmc(filename);
  /**
   * 設置文書(shū)的保存路徑
   */
  wenshu.setWsbclj(filepath);
  /**
   * 設置文書(shū)的類(lèi)型
   */
  wenshu.setWslx(fuf.getLx());
  Date date = new Date();
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  wenshu.setScrq((java.sql.Date.valueOf(format.format(date))));
  /**
   * 檢測文書(shū)是新增還是覆蓋
   */
  Tajws ws = lawCaseDAO.checkWenshuExist(wenshu);
  if (ws == null) {// 新增
   lawCaseDAO.addWenshu(wenshu);
  } else {// 修改
   /**
    * 先刪除后生成
    */
   File f = new File(path + ws.getWsbclj());
   f.delete();
   ws.setWsmc(filename);
   ws.setWsbclj(filepath);
   lawCaseDAO.updateWenshu(ws);
  }
  /**
   * 創(chuàng )建文件
   */
  OutputStream os = new FileOutputStream(path + "/pages/lawcase/wenshu/"
    + urlFileName);

  int readBytes = 0;
  byte buffer[] = new byte[8192];
  InputStream stream = file.getInputStream();
  while ((readBytes = stream.read(buffer, 0, 8192)) != -1) {
   os.write(buffer, 0, readBytes);
  }
  os.close();
  stream.close();
  file.destroy();
  request.setAttribute("message", "上傳成功!");
  return mapping.findForward("success");
 }
下載:
public ActionForward downloadFile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  String path = getServlet().getServletContext().getRealPath("/");
  String sourceFilePathName = request.getParameter("fname");
  File file = new File(path + sourceFilePathName);
  long length = file.length(); // 文件長(cháng)度
  InputStream in = new FileInputStream(file);
  if (in != null) {
   String fs = file.getName();
   response.reset();
   response.setContentType("application/x-msdownload"); //
   String s = "attachment; filename=" + fs; //
   response.setHeader("Content-Disposition", s); // 以上輸出文件元信息
   response.setContentLength((int) length); // 設置輸入文件長(cháng)度
   byte[] b = new byte[2048];
   int len = 0;
   while ((len = in.read(b)) > 0) {
    response.getOutputStream().write(b, 0, len); // 向瀏覽器輸出
   }
   in.close(); // 關(guān)閉文件輸入流
  }
  return null;
 }

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
SSH開(kāi)發(fā)網(wǎng)上商店過(guò)程中遇到的16個(gè)問(wèn)題
基于Struts2 Result Type為chain 的Action之間數據傳遞
struts2多文件動(dòng)態(tài)下載及中文解決方案(此文測試過(guò),沒(méi)錯)
[精]采用dwrajax和struts開(kāi)發(fā)文件上傳進(jìn)度條
Struts迭代器(iterator)遍歷List常用的4種例子
web中使用POI導入導出EXCEL文件的例子
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久