posts - 6, comments - 8, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          [jsp]jspSmartUpload實現(xiàn)文件上傳

          Posted on 2007-04-12 11:03 sxt 閱讀(420) 評論(0)  編輯  收藏 所屬分類: JSP
          index.jsp代碼:

          <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
          <%
          //String path = request.getContextPath();
          //String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>

            <head>
             
             
              <title>My JSP 'index.jsp' starting page</title>
             
              <meta http-equiv="pragma" content="no-cache">
              <meta http-equiv="cache-control" content="no-cache">
              <meta http-equiv="expires" content="0">
              <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              <meta http-equiv="description" content="This is my page">
             
              <!--
              <link rel="stylesheet" type="text/css" href="/blog/styles.css">
              -->
            </head>
           
            <body>
            文件上傳范例-jspsmart
            <form name="form1"  method="post" action="Jspsmart.jsp"  enctype="multipart/form-data">
            <p> 上傳文件1:<INPUT type="file" name="File1" size="20"></p>
            <INPUT type="submit" value="上傳">
            <INPUT type="reset" value="清除">
            </form>
            </body>
          </html>

          Jspsmart.jsp代碼:


          <%@ page language="java" import="com.jspsmart.upload.*" pageEncoding="GB2312"%>


          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>

            <head>
             
              <title>My JSP 'Jspsmart.jsp' starting page</title>
             
              <meta http-equiv="pragma" content="no-cache">
              <meta http-equiv="cache-control" content="no-cache">
              <meta http-equiv="expires" content="0">
              <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              <meta http-equiv="description" content="This is my page">

            </head>
           
            <body>
              <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
              <%
               int count=0;
               mySmartUpload.initialize(pageContext);
               mySmartUpload.setMaxFileSize(5*1024*1024);
               mySmartUpload.upload();
               out.print("mySmartUpload.upload()<br>");
               try{
               // mySmartUpload.getFiles().getFile(0).saveAs("D:\\aaa\\1212.rar",mySmartUpload.SAVE_PHYSICAL);
                count = mySmartUpload.save("file\\");
                out.print("count = mySmartUpload.save(d:\\aaa\\);<br>");
               }
               catch(Exception e){
                out.println(e.toString());
               }
              %>
              skdfjskfjksdjfj
              <br>
            </body>
          </html>


          其中加粗的紅色字體是必須要有的。

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 德昌县| 遂昌县| 洞头县| 错那县| 张家界市| 大洼县| 西安市| 繁昌县| 长顺县| 凯里市| 贺兰县| 科尔| 和静县| 勐海县| 阳江市| 哈尔滨市| 石门县| 沙田区| 兴文县| 梅河口市| 霍邱县| 华亭县| 咸宁市| 龙海市| 江川县| 长汀县| 琼结县| 临沂市| 林芝县| 平湖市| 玉屏| 亳州市| 桃江县| 东光县| 贵溪市| 临清市| 原阳县| 临澧县| 剑川县| 潮安县| 郧西县|