Study java

          一個(gè)新手學(xué)習(xí)JavaEE的心得,希望對學(xué)習(xí)JavaEE的朋友有些幫助。

          用jspsmart 進(jìn)行上傳


          首先去http://www.jspsmart.com下載jspSmartUpload.zip,解壓縮后將文件放在WEB-INF/classes/下(目前這個(gè)網(wǎng)站已經(jīng)被關(guān)閉)
          本地下載
          下面是演示。SmartUpLoad只有一個(gè)構(gòu)造函數(shù)。即public SmartUpload在jsp中直接使用javaBean來生成一個(gè)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"/>
          <%
          //計(jì)算文件上傳個(gè)數(shù)
          int?count=0;

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

          //依據(jù)form的內(nèi)容上傳
          mySmartUpload.upload();

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

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

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

          mySmartUpload.SAVE_PHYSICAL);

          //顯示此上傳文件的詳細(xì)信息
          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?
          ++;
          }
          }

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

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

          </body>
          </html>



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

          評論

          # re: 用jspsmart 進(jìn)行上傳 2010-05-05 13:46 asdas

          編碼問題如何解決?  回復(fù)  更多評論   


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


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          城市流浪者

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 房产| 乐昌市| 沾化县| 普定县| 泰和县| 乐都县| 无棣县| 河源市| 连山| 维西| 齐齐哈尔市| 雅安市| 罗平县| 南溪县| 会宁县| 观塘区| 刚察县| 罗江县| 恩施市| 宁海县| 星座| 大英县| 徐闻县| 哈尔滨市| 河津市| 牟定县| 德兴市| 玛多县| 彭州市| 东丽区| 新野县| 平谷区| 盘山县| 三台县| 观塘区| 永嘉县| 新干县| 桓台县| 濮阳县| 应城市| 南康市|