Study java

          一個新手學習JavaEE的心得,希望對學習JavaEE的朋友有些幫助。

          用jspsmart 進行上傳


          首先去http://www.jspsmart.com下載jspSmartUpload.zip,解壓縮后將文件放在WEB-INF/classes/下(目前這個網站已經被關閉)
          本地下載
          下面是演示。SmartUpLoad只有一個構造函數。即public SmartUpload在jsp中直接使用javaBean來生成一個SmartUpLoad的對象
          <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
          下面是演示。其中方法都是有注釋的
          ------------------------------Jspsmart.html---------------
          < html >
          < head >
          < title > Jspsmart.html </ title >
          < meta? http-equiv ="Content-Type" ?content ="text/html;?charset=GB2312" >
          </ head >
          < body >

          < h2 > 文件上傳范例?-?jspSmart </ h2 >

          < form? name ="Form1" ?enctype ="multipart/form-data" ?method ="post" ?action ="Jspsmart.jsp" >
          < p > 上傳文件?1: < input? type ="file" ?name ="File1" ?size ="20" maxlength ="20" ></ p >
          < p > 上傳文件?2: < input? type ="file" ?name ="File2" ?size ="20" maxlength ="20" ></ p >
          < input? type ="submit" ?value ="上傳" >
          < input? type ="reset" ?value ="清除" >
          </ form >

          </ body >
          </ html >



          ------------------------------------Jspsmart.jsp--------------------



          <%@?page?import="com.jspsmart.upload.*"?%>
          <%@?page?contentType="text/html;charset=GB2312"?%>

          <html>
          <head>
          <title>CH9?-?Jspsmart2.jsp</title>
          </head>
          <body>

          <h2>文件上傳范例?-?jspSmart</h2>

          <jsp:useBean?id="mySmartUpload"?scope="page"?class="com.jspsmart.upload.SmartUpload"/>
          <%
          //計算文件上傳個數
          int?count=0;

          //SmartUpload的初始化,使用這個jspsmart一定要在一開始就這樣聲明
          mySmartUpload.initialize(pageContext);

          //依據form的內容上傳
          mySmartUpload.upload();

          //將上傳的文件一個一個取出來處理
          for?(int?i=0;i<mySmartUpload.getFiles().getCount();i++)
          {
          //取出一個文件
          com.jspsmart.upload.File?myFile?
          =?mySmartUpload.getFiles().getFile(i);

          //如果文件存在,則做存檔操作
          if?(!myFile.isMissing())?{

          //將文件存放于絕對路徑的位置
          myFile.saveAs(
          "C:\\upload\\"?+?myFile.getFileName(),

          mySmartUpload.SAVE_PHYSICAL);

          //顯示此上傳文件的詳細信息
          out.println(
          "FieldName?=?"?+?myFile.getFieldName()?+?"<BR>");
          out.println(
          "Size?=?"?+?myFile.getSize()?+?"<BR>");
          out.println(
          "FileName?=?"?+?myFile.getFileName()?+?"<BR>");
          out.println(
          "FileExt?=?"?+?myFile.getFileExt()?+?"<BR>");
          out.println(
          "FilePathName?=?"?+?myFile.getFilePathName()?+?"<BR>");
          out.println(
          "ContentType?=?"?+?myFile.getContentType()?+?"<BR>");
          out.println(
          "ContentDisp?=?"?+?myFile.getContentDisp()?+"<BR>");
          out.println(
          "TypeMIME?=?"?+?myFile.getTypeMIME()?+"<BR>");
          out.println(
          "SubTypeMIME?=?"?+?myFile.getSubTypeMIME()?+?"<BR>");
          count?
          ++;
          }
          }

          //?顯示應該上傳的文件數目
          out.println(
          "<BR>"?+?mySmartUpload.getFiles().getCount()?+?"?files?could?be?uploaded.<BR>");

          //?顯示成功上傳的文件數目
          out.println(count?
          +?"file(s)?uploaded.");
          %>

          </body>
          </html>



          posted on 2006-11-10 18:39 ronghai 閱讀(4373) 評論(1)  編輯  收藏 所屬分類: jsp學習

          評論

          # re: 用jspsmart 進行上傳 2010-05-05 13:46 asdas

          編碼問題如何解決?  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2006年11月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          城市流浪者

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 云阳县| 隆安县| 刚察县| 土默特左旗| 大悟县| 行唐县| 井冈山市| 梁平县| 开封市| 洪泽县| 望都县| 平泉县| 应城市| 大庆市| 萨嘎县| 三明市| 札达县| 嘉祥县| 肃北| 洞口县| 永昌县| 肥西县| 富源县| 保德县| 台州市| 长治县| 桂东县| 于田县| 霸州市| 财经| 博爱县| 同仁县| 永昌县| 乡城县| 河池市| 太仓市| 阿坝| 九龙县| 商丘市| 多伦县| 榕江县|