<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

         <form-bean name="fileUploadForm" type="org.apache.struts.action.DynaActionForm">
           <form-property name="fileName" type="Java.lang.String"></form-property>
           <form-property name="docfile" type="org.apache.struts.upload.FormFile"/>
           <form-property name="fileDescription" type="Java.lang.String"></form-property>
        </form-bean>


    <form name="form1" method="post" action="<%=request.getContextPath()%>/fileUpload.do?method=upload" enctype="multipart/form-data">
      <table width="43%" border="1" align="center">
        <tr>
          <td colspan="2"><div align="center">上傳周報</div></td>
        </tr>
        <tr>
          <td width="22%">文件名稱</td>
          <td width="78%"><input type="text" name="fileName"></td>
        </tr>
        <tr>
          <td width="22%">選擇文件</td>
          <td width="78%"><input type="file" name="docfile"/></td>
        </tr>
        <tr>
          <td width="22%">文件描述</td>
          <td><input type="textarea" name="fileDescription"/></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><input type="submit" name="Submit" value="上傳"><input type="reset" name="Submit2" value="重置"></td>
        </tr>
      </table>


    public ActionForward upload(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
      request.setCharacterEncoding("UTF-8");
      DynaActionForm dynaform = (DynaActionForm) form;
      FormFile docfile = (FormFile) dynaform.get("docfile");
      String fileName=dynaform.get("fileName").toString();
      String fileDescription=(String) dynaform.get("fileDescription");
      if (docfile == null) {
       return mapping.getInputForward();
      }
      if (docfile.getFileSize() == 0) {
       request.getSession().setAttribute("message", "未選中文件或文件大小為零!");
       return mapping.getInputForward();
      }
      String ctype = docfile.getContentType();
      if (ctype.indexOf("doc") != -1) {
       request.getSession().setAttribute("message", "文件類型錯誤!");
       return mapping.getInputForward();
      }
      // 寫文件
      BufferedInputStream bis = null;
      BufferedOutputStream bos = null;
      InputStream is = null;
      OutputStream fos = null;

      String filename = "";
      String filePath = "";
      try {
       is = (InputStream) docfile.getInputStream();// 把文件讀入
       bis = new BufferedInputStream(is);

       filePath ="E:/upload/";// 取當前系統路徑
       File rootfile = new File(filePath);
       if (!rootfile.exists()) {
        rootfile.mkdirs();
       }
       String name= new String(docfile.getFileName().getBytes("UTF-8"),"gb2312");
       filename = new Date().getTime()+request.getSession().getId()+fileName+".doc";
      fos = new FileOutputStream(filePath + filename);// 建立一個上傳文件的輸出流
       bos = new BufferedOutputStream(fos);
       int bytesRead = 0;
       byte[] buffer = new byte[2 * 1024];
       while ((bytesRead = bis.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);// 將文件寫入服務器
       }
       FileUpload fileUpload=new FileUpload();
       fileUpload.setFileName(fileName);
       fileUpload.setFilePath(filePath+filename);
       fileUpload.setFileDescription(fileDescription);
       this.getSiteBusiness().getFileLoadService().save(fileUpload);
       return mapping.findForward("uploadsucess");
      }catch (Exception e) {
       e.printStackTrace();
       return mapping.getInputForward();
      } finally {
       if (bos != null) {
        try {
         bos.close();
        } catch (IOException e) {
         System.err.print(e);
         return mapping.getInputForward();
        }
       }
       if (bis != null) {
        try {
         bis.close();
        } catch (IOException e) {
         System.err.print(e);
         return mapping.getInputForward();
        }
       }
      }

     }

    posted on 2007-01-30 11:40 周銳 閱讀(551) 評論(2)  編輯  收藏 所屬分類: Struts
    主站蜘蛛池模板: 免费无码又爽又刺激高潮软件 | 亚洲精品国产精品乱码不卡| xxx毛茸茸的亚洲| 四虎永久在线观看免费网站网址| 亚洲精品资源在线| 国产1000部成人免费视频| 老色鬼久久亚洲AV综合| 久久久久av无码免费网| 亚洲一卡二卡三卡四卡无卡麻豆| 18禁网站免费无遮挡无码中文| 亚洲乱码中文论理电影| 最近的免费中文字幕视频 | 国产羞羞的视频在线观看免费| 亚洲av无码潮喷在线观看| 久久永久免费人妻精品下载| 亚洲精品视频在线观看视频| 国产精品免费观看| 亚洲精品日韩一区二区小说| 亚洲高清视频一视频二视频三| 国产精品成人免费观看| 亚洲av永久无码制服河南实里| 67pao强力打造高清免费| 亚洲中文字幕乱码熟女在线| 日产国产精品亚洲系列| 免费91麻豆精品国产自产在线观看| 久久久婷婷五月亚洲97号色| 成人在线视频免费| 中国黄色免费网站| 亚洲天堂中文字幕在线观看| 日韩午夜免费视频| 在线观看免费无码专区 | 亚洲妇女无套内射精| 亚洲精品无码专区2| 99在线视频免费| 亚洲αⅴ无码乱码在线观看性色| 亚洲精品视频在线看| 91久久青青草原线免费| 日韩亚洲人成网站| 亚洲情a成黄在线观看动漫尤物| 成人黄软件网18免费下载成人黄18免费视频 | 国产网站在线免费观看|