<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 周銳 閱讀(562) 評論(2)  編輯  收藏 所屬分類: Struts
    主站蜘蛛池模板: 亚洲视频在线播放| 国产日产亚洲系列最新| 久久久亚洲AV波多野结衣| 国产在线国偷精品免费看| 亚洲 暴爽 AV人人爽日日碰| 免费人成视频在线观看网站| 亚洲大片在线观看| 久久aⅴ免费观看| 亚洲自偷精品视频自拍| 6080午夜一级毛片免费看| 亚洲精品视频观看| 亚洲免费综合色在线视频| 亚洲砖码砖专无区2023 | 亚洲沟沟美女亚洲沟沟| 国产高清免费视频| 中国亚洲呦女专区| 免费在线观看的黄色网址| 国产成人久久精品亚洲小说| 亚洲麻豆精品国偷自产在线91| eeuss影院www天堂免费| 久久青青成人亚洲精品| 久久久久久曰本AV免费免费| 久久精品国产亚洲av麻豆图片 | 最近免费中文字幕大全免费版视频| 内射干少妇亚洲69XXX| 中国在线观看免费国语版| 亚洲第一第二第三第四第五第六| 四虎影院永久免费观看| 99精品免费视频| 91午夜精品亚洲一区二区三区| 四虎在线免费播放| 亚欧乱色国产精品免费视频| 亚洲国产精品一区| 四虎成人免费观看在线网址| 99免费精品视频| 亚洲综合久久一本伊伊区| 亚洲国产成人久久综合碰| 无码人妻丰满熟妇区免费| 99热亚洲色精品国产88| 久久影院亚洲一区| 欧美三级在线电影免费|