陌上花開

          遇高山,我御風(fēng)而翔,逢江河,我凌波微波

             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::

          2012年12月20日 #

          標(biāo)準(zhǔn)javascript 是內(nèi)含支持hash關(guān)聯(lián)數(shù)組,經(jīng)查找資料并測試,有關(guān)標(biāo)準(zhǔn)javascript內(nèi)含的hash關(guān)聯(lián)數(shù)組操作備忘如下

          1。Hash關(guān)聯(lián)數(shù)組定義

          // 定義空數(shù)組
          myhash = { }

          // 直接定義數(shù)組
          myhash = {”key1″:”val1″, “key2″:”val2″ }

          // 用Array 定義數(shù)組
          myhash = new Array();
          myhash[”key1″] = “val1″;
          myhash[”key2″] = “val2″;

          2。向Hash關(guān)聯(lián)數(shù)組添加鍵值

          // 添加一個(gè)新鍵 newkey ,鍵值為 newval
          myhash[”newkey”] = “newval”;

          3。刪除Hash關(guān)聯(lián)數(shù)組已有鍵值

          // 刪除一個(gè)鍵 newkey ,同時(shí),該鍵值對(duì)應(yīng)的 newval 也就消失了
          delete myhash[”newkey”];

          4。遍歷Hash關(guān)聯(lián)數(shù)組

          // 遍歷整個(gè)hash 數(shù)組
          for (key in myhash) {
          val = myhash[key];
          }

          5。Hash關(guān)聯(lián)數(shù)組簡易使用示例

          // 轉(zhuǎn)向腳本
          <script type=”text/javascript”>
          urlhash = { “yahoo”:”www.yahoo.cn“,
          “baidu”:”www.baidu.com“,
          “google”:”www.google.cn” };

          // 交互式使用示例
          userinfo = prompt(”請(qǐng)輸入您最想去的搜索引擎:(yahoo|baidu|google)”, “yahoo”);
          document.write (”您的選擇:” + userinfo + “,<a href=http://” + getURL(userinfo) + ” target=_blank>” + “按此即可進(jìn)入” + “</a>” + userinfo + “。”);

          // getURL
          // 如果參數(shù)未定義,默認(rèn)返回 www.yahoo.cn 網(wǎng)址
          // @param choice 選擇名稱
          // @return url 實(shí)際的URL
          function getURL(choice) {
          url = urlhash[choice];
          if (typeof(urlhash[choice]) == “undefined”)
          url = “www.yahoo.cn“;
          return url;
          }

          // 獲得hash列表的所有 keys
          // @param hash hash數(shù)組
          // @return keys 鍵名數(shù)據(jù)
          function array_keys(hash) {
          keys = [];
          for (key in hash)
          keys.push(key);
          return keys;
          }
          </script>

          posted @ 2012-12-20 11:28 askzs 閱讀(18381) | 評(píng)論 (1)編輯 收藏

          2012年11月20日 #

          原文地址:http://www.cnblogs.com/Lewis/archive/2010/04/27/1722024.html

           

          關(guān)于JQuery上傳插件Uploadify使用詳解網(wǎng)上一大把,基本上內(nèi)容都一樣。我根據(jù)網(wǎng)上的步驟配置成功后,會(huì)報(bào)一些錯(cuò)誤,而我根據(jù)這些錯(cuò)誤去網(wǎng)上找解決方案,卻沒有相關(guān)資料,所以為了不讓更多的朋友走彎路,我把我遇到的一些問題進(jìn)行匯總,也方便我自己以后查閱。

            什么是Uploadify

            Uploadify是JQuery的一個(gè)上傳插件,支持多文件上傳,實(shí)現(xiàn)的效果非常不錯(cuò),帶進(jìn)度顯示。

            官網(wǎng)提供的是PHP的DEMO,在這里我詳細(xì)介紹在Asp.net下的使用.

            下載

              官方下載

              官方文檔

              官方演示

            如何使用

            1 創(chuàng)建Web項(xiàng)目,命名為JQueryUploadDemo,從官網(wǎng)上下載最新的版本解壓后添加到項(xiàng)目中

            2 在項(xiàng)目中添加UploadHandler.ashx文件用來處理文件的上傳。

            3 在項(xiàng)目中添加UploadFile文件夾,用來存放上傳的文件。

            進(jìn)行完上面三步后項(xiàng)目的基本結(jié)構(gòu)如下圖:

            

            4 Default.aspx的html頁的代碼修改如下:

            

          <html xmlns="http://www.w3.org/1999/xhtml">
          <head runat="server">
             
          <title>Uploadify</title>
             
          <link href="JS/jquery.uploadify-v2.1.0/example/css/default.css"
               rel
          ="stylesheet" type="text/css" />
             
          <link href="JS/jquery.uploadify-v2.1.0/uploadify.css"
               rel
          ="stylesheet" type="text/css" />

             
          <script type="text/javascript"
               src
          ="JS/jquery.uploadify-v2.1.0/jquery-1.3.2.min.js"></script>

             
          <script type="text/javascript"
               src
          ="JS/jquery.uploadify-v2.1.0/swfobject.js"></script>

             
          <script type="text/javascript"
             src
          ="JS/jquery.uploadify-v2.1.0/jquery.uploadify.v2.1.0.min.js"></script>

             
          <script type="text/javascript">
                  $(document).ready(
          function()
                  {
                      $(
          "#uploadify").uploadify({
                         
          'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
                         
          'script': 'UploadHandler.ashx',
                         
          'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png',
                         
          'folder': 'UploadFile',
                         
          'queueID': 'fileQueue',
                         
          'auto': false,
                         
          'multi': true
                      });
                  }); 
             
          </script>

          </head>
          <body>
             
          <div id="fileQueue"></div>
             
          <input type="file" name="uploadify" id="uploadify" />
             
          <p>
               
          <a href="javascript:$('#uploadify').uploadifyUpload()">上傳</a>|
               
          <a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上傳</a>
             
          </p>
          </body>
          </html>

            5  UploadHandler類的ProcessRequest方法代碼如下:

            

          public void ProcessRequest(HttpContext context)
          {
              context.Response.ContentType
          = "text/plain";  
              context.Response.Charset
          = "utf-8";  

              HttpPostedFile file
          = context.Request.Files["Filedata"];  
             
          string  uploadPath =
                  HttpContext.Current.Server.MapPath(@context.Request[
          "folder"])+"\\"

             
          if (file != null
              { 
                
          if (!Directory.Exists(uploadPath)) 
                 { 
                     Directory.CreateDirectory(uploadPath); 
                 }  
                 file.SaveAs(uploadPath
          + file.FileName); 
                 
          //下面這句代碼缺少的話,上傳成功后上傳隊(duì)列的顯示不會(huì)自動(dòng)消失
                 context.Response.Write("1"); 
              }  
             
          else 
              {  
                  context.Response.Write(
          "0");  
              } 
          }

            注意:這里一定要注意,一定要引用using System.IO;命名空間,我出錯(cuò)的原因也是在這里,網(wǎng)上的教程基本上都沒提到這一點(diǎn),所以有很多網(wǎng)友會(huì)遇到IOError的錯(cuò)誤。

          6 運(yùn)行后效果如下圖:

            

            7 選擇了兩個(gè)文件后,點(diǎn)擊上傳,就可以看到UploadFile文件夾中會(huì)增加這兩個(gè)文件。

            

            上面的代碼就簡單實(shí)現(xiàn)了上傳的功能,依靠函數(shù)uploadify實(shí)現(xiàn),uploadify函數(shù)的參數(shù)為json格式,可以對(duì)json對(duì)象的key值的修改來進(jìn)行自定義的設(shè)置,如multi設(shè)置為true或false來控制是否可以進(jìn)行多文件上傳,下面就來介紹下這些key值的意思:

           

          uploader : uploadify.swf 文件的相對(duì)路徑,該swf文件是一個(gè)帶有文字BROWSE的按鈕,點(diǎn)擊后淡出打開文件對(duì)話框,默認(rèn)值:uploadify.swf。
          script :   后臺(tái)處理程序的相對(duì)路徑 。默認(rèn)值:uploadify.php
          checkScript :用來判斷上傳選擇的文件在服務(wù)器是否存在的后臺(tái)處理程序的相對(duì)路徑
          fileDataName :設(shè)置一個(gè)名字,在服務(wù)器處理程序中根據(jù)該名字來取上傳文件的數(shù)據(jù)。默認(rèn)為Filedata
          method : 提交方式Post 或Get 默認(rèn)為Post
          scriptAccess :flash腳本文件的訪問模式,如果在本地測試設(shè)置為always,默認(rèn)值:sameDomain 
          folder :  上傳文件存放的目錄 。
          queueID : 文件隊(duì)列的ID,該ID與存放文件隊(duì)列的div的ID一致。
          queueSizeLimit : 當(dāng)允許多文件生成時(shí),設(shè)置選擇文件的個(gè)數(shù),默認(rèn)值:999 。
          multi : 設(shè)置為true時(shí)可以上傳多個(gè)文件。
          auto : 設(shè)置為true當(dāng)選擇文件后就直接上傳了,為false需要點(diǎn)擊上傳按鈕才上傳 。
          fileDesc : 這個(gè)屬性值必須設(shè)置fileExt屬性后才有效,用來設(shè)置選擇文件對(duì)話框中的提示文本,如設(shè)置fileDesc為“請(qǐng)選擇rar doc pdf文件”,打開文件選擇框效果如下圖:

            

          fileExt : 設(shè)置可以選擇的文件的類型,格式如:'*.doc;*.pdf;*.rar' 。
          sizeLimit : 上傳文件的大小限制 。
          simUploadLimit : 允許同時(shí)上傳的個(gè)數(shù) 默認(rèn)值:1 。
          buttonText : 瀏覽按鈕的文本,默認(rèn)值:BROWSE 。
          buttonImg : 瀏覽按鈕的圖片的路徑 。
          hideButton : 設(shè)置為true則隱藏瀏覽按鈕的圖片 。
          rollover : 值為true和false,設(shè)置為true時(shí)當(dāng)鼠標(biāo)移到瀏覽按鈕上時(shí)有反轉(zhuǎn)效果。
          width : 設(shè)置瀏覽按鈕的寬度 ,默認(rèn)值:110。
          height : 設(shè)置瀏覽按鈕的高度 ,默認(rèn)值:30。
          wmode : 設(shè)置該項(xiàng)為transparent 可以使瀏覽按鈕的flash背景文件透明,并且flash文件會(huì)被置為頁面的最高層。 默認(rèn)值:opaque 。
          cancelImg :選擇文件到文件隊(duì)列中后的每一個(gè)文件上的關(guān)閉按鈕圖標(biāo),如下圖:

            

          上面介紹的key值的value都為字符串或是布爾類型,比較簡單,接下來要介紹的key值的value為一個(gè)函數(shù),可以在選擇文件、出錯(cuò)或其他一些操作的時(shí)候返回一些信息給用戶。

          onInit : 做一些初始化的工作

          onSelect :選擇文件時(shí)觸發(fā),該函數(shù)有三個(gè)參數(shù)

          • event:事件對(duì)象。
          • queueID:文件的唯一標(biāo)識(shí),由6為隨機(jī)字符組成。
          • fileObj:選擇的文件對(duì)象,有name、size、creationDate、modificationDate、type 5個(gè)屬性。

          代碼如下:

            

          $(document).ready(function()
          {
              $(
          "#uploadify").uploadify({
                 
          'uploader': 'JS/jquery.uploadify-v2.1.0/uploadify.swf',
                 
          'script': 'UploadHandler.ashx',
                 
          'cancelImg': 'JS/jquery.uploadify-v2.1.0/cancel.png',
                 
          'folder': 'UploadFile',
                 
          'queueID': 'fileQueue',
                 
          'auto': false,
                 
          'multi': true,
                 
          'onInit':function(){alert("1");},
                 
          'onSelect': function(e, queueId, fileObj)
                  {
                      alert(
          "唯一標(biāo)識(shí):" + queueId + "\r\n" +
                           
          "文件名:" + fileObj.name + "\r\n" +
                           
          "文件大小:" + fileObj.size + "\r\n" +
                           
          "創(chuàng)建時(shí)間:" + fileObj.creationDate + "\r\n" +
                           
          "最后修改時(shí)間:" + fileObj.modificationDate + "\r\n" +
                           
          "文件類型:" + fileObj.type
                      );

                  }
              });
          }); 

           


          當(dāng)選擇一個(gè)文件后彈出的消息如下圖:

          onSelectOnce :在單文件或多文件上傳時(shí),選擇文件時(shí)觸發(fā)。該函數(shù)有兩個(gè)參數(shù)event,data,data對(duì)象有以下幾個(gè)屬性:

          fileCount:選擇文件的總數(shù)。
          filesSelected:同時(shí)選擇文件的個(gè)數(shù),如果一次選擇了3個(gè)文件該屬性值為3。
          filesReplaced:如果文件隊(duì)列中已經(jīng)存在A和B兩個(gè)文件,再次選擇文件時(shí)又選擇了A和B,該屬性值為2。
          allBytesTotal:所有選擇的文件的總大小。
           

          onCancel : 當(dāng)點(diǎn)擊文件隊(duì)列中文件的關(guān)閉按鈕或點(diǎn)擊取消上傳時(shí)觸發(fā)。該函數(shù)有event、queueId、fileObj、data四個(gè)參數(shù),前三個(gè)參數(shù)同onSelect 中的三個(gè)參數(shù),data對(duì)象有兩個(gè)屬性fileCount和allBytesTotal。

          fileCount:取消一個(gè)文件后,文件隊(duì)列中剩余文件的個(gè)數(shù)。
          allBytesTotal:取消一個(gè)文件后,文件隊(duì)列中剩余文件的大小。
           

          onClearQueue :當(dāng)調(diào)用函數(shù)fileUploadClearQueue時(shí)觸發(fā)。有event和data兩個(gè)參數(shù),同onCancel 中的兩個(gè)對(duì)應(yīng)參數(shù)。

          onQueueFull :當(dāng)設(shè)置了queueSizeLimit并且選擇的文件個(gè)數(shù)超出了queueSizeLimit的值時(shí)觸發(fā)。該函數(shù)有兩個(gè)參數(shù)event和queueSizeLimit。

          onError :當(dāng)上傳過程中發(fā)生錯(cuò)誤時(shí)觸發(fā)。該函數(shù)有event、queueId、fileObj、errorObj四個(gè)參數(shù),其中前三個(gè)參數(shù)同上,errorObj對(duì)象有type和info兩個(gè)屬性。

          type:錯(cuò)誤的類型,有三種‘HTTP’, ‘IO’, or ‘Security’
          info:錯(cuò)誤的描述
           

          onOpen :點(diǎn)擊上傳時(shí)觸發(fā),如果auto設(shè)置為true則是選擇文件時(shí)觸發(fā),如果有多個(gè)文件上傳則遍歷整個(gè)文件隊(duì)列。該函數(shù)有event、queueId、fileObj三個(gè)參數(shù),參數(shù)的解釋同上。

          onProgress :點(diǎn)擊上傳時(shí)觸發(fā),如果auto設(shè)置為true則是選擇文件時(shí)觸發(fā),如果有多個(gè)文件上傳則遍歷整個(gè)文件隊(duì)列,在onOpen之后觸發(fā)。該函數(shù)有event、queueId、fileObj、data四個(gè)參數(shù),前三個(gè)參數(shù)的解釋同上。data對(duì)象有四個(gè)屬性percentage、bytesLoaded、allBytesLoaded、speed:

          percentage:當(dāng)前完成的百分比
          bytesLoaded:當(dāng)前上傳的大小
          allBytesLoaded:文件隊(duì)列中已經(jīng)上傳完的大小
          speed:上傳速率 kb/s
           

          onComplete:文件上傳完成后觸發(fā)。該函數(shù)有四個(gè)參數(shù)event、queueId、fileObj、response、data五個(gè)參數(shù),前三個(gè)參數(shù)同上。response為后臺(tái)處理程序返回的值,在上面的例子中為1或0,data有兩個(gè)屬性fileCount和speed

          fileCount:剩余沒有上傳完成的文件的個(gè)數(shù)。
          speed:文件上傳的平均速率 kb/s
          注:fileObj對(duì)象和上面講到的有些不太一樣,onComplete 的fileObj對(duì)象有個(gè)filePath屬性可以取出上傳文件的路徑。

           

          onAllComplete:文件隊(duì)列中所有的文件上傳完成后觸發(fā)。該函數(shù)有event和data兩個(gè)參數(shù),data有四個(gè)屬性,分別為:

          filesUploaded :上傳的所有文件個(gè)數(shù)。
          errors :出現(xiàn)錯(cuò)誤的個(gè)數(shù)。
          allBytesLoaded :所有上傳文件的總大小。
          speed :平均上傳速率 kb/s
           

          相關(guān)函數(shù)介紹

          在上面的例子中已經(jīng)用了uploadifyUpload和uploadifyClearQueue兩個(gè)函數(shù),除此之外還有幾個(gè)函數(shù):

          uploadifySettings:可以動(dòng)態(tài)修改上面介紹的那些key值,如下面代碼

            $('#uploadify').uploadifySettings('folder','JS'); 

          如果上傳按鈕的事件寫成下面這樣,文件將會(huì)上傳到uploadifySettings定義的目錄中

          <a href="javascript:$('#uploadify').uploadifySettings('folder','JS');$('#uploadify').uploadifyUpload()">上傳</a>

            uploadifyCancel:該函數(shù)接受一個(gè)queueID作為參數(shù),可以取消文件隊(duì)列中指定queueID的文件。

            
            $('#uploadify').uploadifyCancel(id); 

           

            好了,所有的配置都完成了。下面說說我遇到的一些問題。 span style="font-size: 18pt;"> 可能遇到的問題   1.我剛開始配置完成后,并不能正常工作 ,flash(uploadify.swf' )沒有加載。后來我查看jquery.uploadify.v2.1.0.js發(fā)現(xiàn)該插件是利用swfobject.js動(dòng)態(tài)創(chuàng)建的FLASH,后來我單獨(dú)做試驗(yàn)還是不能顯示flash,無耐之下重啟電腦后就可以了。暈倒~~~  2.FLASH終于加載進(jìn)來了,但上傳又失敗了。報(bào)IOError,如圖:  

            

          百思不得其解,翻遍了各大網(wǎng)絡(luò),終于在國外的一網(wǎng)站看到了這么一句using System.IO; 添加之豁然開朗!!

          暫時(shí)還沒有遇到其它問題,后續(xù)發(fā)現(xiàn)問題再加。

          posted @ 2012-11-20 11:41 askzs 閱讀(1166) | 評(píng)論 (0)編輯 收藏

          2012年8月13日 #

          ThickBox 是基于 jQuery 用 JavaScript 編寫的網(wǎng)頁UI對(duì)話窗口小部件. 它可以用來展示單一圖片, 若干圖片, 內(nèi)嵌的內(nèi)容, iframed的內(nèi)容, 或以 AJAX 的混合 modal 提供的內(nèi)容.

          特性:

          • ThickBox 是用超輕量級(jí)的 jQuery 庫 編寫的. 壓縮過 jQuery 庫只15k, 未壓縮過的有39k.
          • ThickBox 的 JavaScript 代碼和 CSS 文件只占12k. 所以壓縮過的 jQuery 代碼和 ThickBox 總共只有27k.
          • ThickBox 能重新調(diào)整大于瀏覽器窗口的圖片.
          • ThickBox 的多功能性包括 (圖片, iframed 的內(nèi)容, 內(nèi)嵌的內(nèi)容, 和 AJAX 的內(nèi)容).
          • ThickBox 能隱藏 Windows IE 6 里的元素.
          • ThickBox 能在使用者滾動(dòng)頁面或改變?yōu)g覽器窗口大小的同時(shí)始終保持居中. 點(diǎn)擊圖片, 覆蓋層, 或關(guān)閉鏈接能移除 ThickBox.
          • ThickBox 的創(chuàng)作者決定動(dòng)畫應(yīng)該因人而異, 所以 ThickBox 不再使用動(dòng)畫了. 這是特性嗎? 哦, 有人說是呀.

          下載

          posted @ 2012-08-13 11:06 askzs 閱讀(308) | 評(píng)論 (0)編輯 收藏

          在項(xiàng)目中,需要用到打印,最早的是使用js調(diào)用本地打印,效果不好,樣式等不好控制,容易出錯(cuò),有時(shí)候?yàn)g覽器不兼容造成不能打印,后來用報(bào)表,生成破地方格式的然后打印,兼容性強(qiáng),穩(wěn)定,比較好用,基本上沒有什么問題,但是開發(fā)過程慢,報(bào)表不好畫,action不好控制,總之,開發(fā)過程比較痛苦,而且樣式變的話報(bào)表需要重新畫,不好修改,后來發(fā)現(xiàn)了 lodop,是個(gè)瀏覽器的插件,需要客戶安裝,安裝后使用方便,打印效果不錯(cuò),還可以讓用戶自己調(diào)試打印模式,而且支持的打印種類多,可以打印背景圖片,套表格式等,就是很方便就是了,安裝也方便,下面是詳細(xì)的介紹說明。
          http://mtsoftware.v053.gokao.net/samples/PrintSampIndex.html

          最新版本及其技術(shù)手冊(cè)可從如下地址下載:
          http://mtsoftware.v053.gokao.net/download.html
          http://mt.runon.cn/download.html 


          posted @ 2012-08-13 09:35 askzs 閱讀(1353) | 評(píng)論 (4)編輯 收藏

          2012年6月5日 #

          在Java中有時(shí)候需要使程序暫停一點(diǎn)時(shí)間,稱為延時(shí)。普通延時(shí)用Thread.sleep(int)方法,這很簡單。它將當(dāng)前線程掛起指定的毫秒數(shù)。如

          Java 代碼復(fù)制內(nèi)容到剪貼板
          1. try
          2. {
          3. Thread.currentThread().sleep(1000);//毫秒
          4. }
          5. catch(Exception e){}

          在這里需要解釋一下線程沉睡的時(shí)間。sleep()方法并不能夠讓程序"嚴(yán)格"的沉睡指定的時(shí)間。例如當(dāng)使用5000作為sleep()方法的參數(shù)時(shí),線 程可能在實(shí)際被掛起5000.001毫秒后才會(huì)繼續(xù)運(yùn)行。當(dāng)然,對(duì)于一般的應(yīng)用程序來說,sleep()方法對(duì)時(shí)間控制的精度足夠了。

          但是如果要使用精確延時(shí),最好使用Timer類:

          Java 代碼復(fù)制內(nèi)容到剪貼板
          1. Timer timer=new Timer();//實(shí)例化Timer類
          2. timer.schedule(new TimerTask(){
          3. public void run(){
          4. System.out.println("退出");
          5. this.cancel();}},500);//五百毫秒

          這種延時(shí)比sleep精確。上述延時(shí)方法只運(yùn)行一次,
          如果需要運(yùn)行多次, 使用timer.schedule(new MyTask(), 1000, 2000); 則每間隔2秒執(zhí)行MyTask()

          posted @ 2012-06-05 11:35 askzs 閱讀(362) | 評(píng)論 (0)編輯 收藏

          2012年5月30日 #

          本課題參考自《Spring in action》。并非應(yīng)用系統(tǒng)中發(fā)生的所有事情都是由用戶的動(dòng)作引起的。有時(shí)候,系統(tǒng)自己也需要發(fā)起一些動(dòng)作。例如,集抄系統(tǒng)每天早上六點(diǎn)把抄表數(shù)據(jù)傳送 給營銷系統(tǒng)。我們有兩種選擇:或者是每天由用戶手動(dòng)出發(fā)任務(wù),或者讓應(yīng)用系統(tǒng)中按照預(yù)定的計(jì)劃自動(dòng)執(zhí)行任務(wù)。 
          在Spring中有兩種流行配置:Java的Timer類和OpenSymphony的Quartz來執(zhí)行調(diào)度任務(wù)。下面以給商丘做的接口集抄900到中間庫的日凍結(jié)數(shù)據(jù)傳輸為例: 

          1. Java Timer調(diào)度器 
          首先定義一個(gè)定時(shí)器任務(wù),繼承java.util.TimerTask類實(shí)現(xiàn)run方法 
          import java.util.TimerTask; 
          import xj.service.IJdbc1Service; 
          import xj.service.IJdbc2Service; 
          public class DayDataTimerTask extends TimerTask{ 
          private IJdbc2Service jdbc2Service=null; 
          private IJdbc1Service jdbc1Service=null; 
          public void run(){ 
          SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
          System.out.println("日凍結(jié)轉(zhuǎn)接任務(wù)開始時(shí)間:"+df.format(Calendar.getInstance().getTime())); 
          System.out.println("日凍結(jié)轉(zhuǎn)接任務(wù)結(jié)束時(shí)間:"+df.format(Calendar.getInstance().getTime())); 


          //通過set方法獲取service服務(wù),如果沒有該方法,則為null 
          public void setJdbc2Service(IJdbc2Service jdbc2Service) { 
          this.jdbc2Service = jdbc2Service; 


          public void setJdbc1Service(IJdbc1Service jdbc1Service) { 
          this.jdbc1Service = jdbc1Service; 


          Run()方法定義了當(dāng)任務(wù)運(yùn)行時(shí)該做什么。jdbc1Service,jdbc2Service通過依賴注入的方式提供給DayDataTimerTask。如果該任務(wù)中沒有service服務(wù)的set方法,則取到的該service服務(wù)為null。 
          其次,在Spring配置文件中聲明 dayDataTimerTask: 
          <!-- 聲明定時(shí)器任務(wù) --> 
          <bean id="dayDataTimerJob" class="xj.action.DayDataTimerTask"> 
          <property name="jdbc1Service"> 
          <ref bean="jdbc1Service"/> 
          </property> 
          <property name="jdbc2Service"> 
          <ref bean="jdbc2Service"/> 
          </property> 
          </bean> 
          該聲明將DayDataTimerTask放到應(yīng)用上下文中,并在jdbc1Service、jdbc2Service屬性中分別裝配jdbc1Service、jdbc2Service。在調(diào)度它之前,它不會(huì)做任何事情。 
          <!-- 調(diào)度定時(shí)器任務(wù) --> 
          <bean id="scheduledDayDataTimerJob" class="org.springframework.scheduling.timer.ScheduledTimerTask"> 
          <property name="timerTask"> 
          <ref bean="dayDataTimerJob"/> 
          </property> 
          <property name="delay"> 
          <value>3000</value> 
          </property> 
          <property name="period"> 
          <value>864000000</value> 
          </property> 
          </bean> 
          屬性timerTask告訴ScheduledTimerTask運(yùn)行哪個(gè)TimerTask。再次,該屬性裝配了指向 scheduledDayDataTimerJob的一個(gè)引用,它就是DayDataTimerTask。屬性period告訴 ScheduledTimerTask以怎樣的頻度調(diào)用TimerTask的run()方法。該屬性以毫秒作為單位,它被設(shè)置為864000000,指定 這個(gè)任務(wù)應(yīng)該每24小時(shí)運(yùn)行一次。屬性delay允許你指定當(dāng)任務(wù)第一次運(yùn)行之前應(yīng)該等待多久。在此指定DayDataTimerTask的第一次運(yùn)行相 對(duì)于應(yīng)用程序的啟動(dòng)時(shí)間延遲3秒鐘。 
          <!-- 啟動(dòng)定時(shí)器 --> 
          <bean class="org.springframework.scheduling.timer.TimerFactoryBean"> 
          <property name="scheduledTimerTasks"> 
          <list> 
          <ref bean="scheduledDayDataTimerJob"/> 
          </list> 
          </property> 
          </bean> 
          Spring的TimerFactoryBean負(fù)責(zé)啟動(dòng)定時(shí)任務(wù)。屬性scheduledTimerTasks要求一個(gè)需要啟動(dòng)的定時(shí)器任務(wù)的列表。在此只包含一個(gè)指向scheduledDayDataTimerJob的引用。 
              Java Timer只能指定任務(wù)執(zhí)行的頻度,但無法精確指定它何時(shí)運(yùn)行,這是它的一個(gè)局限性。要想精確指定任務(wù)的啟動(dòng)時(shí)間,就需要使用Quartz[kw?:ts]調(diào)度器。 

          2.Quartz調(diào)度器 
          Quartz調(diào)度器不僅可以定義每隔多少毫秒執(zhí)行一個(gè)工作,還允許你調(diào)度一個(gè)工作在某個(gè)特定的時(shí)間或日期執(zhí)行。 
          首先創(chuàng)建一個(gè)工作,繼承QuartzJobBean類實(shí)現(xiàn)executeInternal方法 
          import org.quartz.JobExecutionContext; 
          import org.quartz.JobExecutionException; 
          import org.springframework.dao.DataIntegrityViolationException; 
          import org.springframework.scheduling.quartz.QuartzJobBean; 

          import xj.service.IJdbc1Service; 
          import xj.service.IJdbc2Service; 
          public class DayDataQuartzTask extends QuartzJobBean{ 
          private IJdbc2Service jdbc2Service=null; 
          private IJdbc1Service jdbc1Service=null; 
          protected void executeInternal(JobExecutionContext context) throws JobExecutionException{ 
          SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
          System.out.println("日凍結(jié)轉(zhuǎn)接任務(wù)開始時(shí)間:"+df.format(Calendar.getInstance().getTime())); 
          System.out.println("日凍結(jié)轉(zhuǎn)接任務(wù)結(jié)束時(shí)間:"+df.format(Calendar.getInstance().getTime())); 


          //通過set方法獲取service服務(wù),如果沒有該方法,則為null 
          public void setJdbc2Service(IJdbc2Service jdbc2Service) { 
          this.jdbc2Service = jdbc2Service; 


          public void setJdbc1Service(IJdbc1Service jdbc1Service) { 
          this.jdbc1Service = jdbc1Service; 




          在Spring配置文件中按照以下方式聲明這個(gè)工作: 
          <!-- 定時(shí)啟動(dòng)任務(wù) Quartz--> 
          <!—聲明工作--> 
          <bean id="dayDataJob" class="org.springframework.scheduling.quartz.JobDetailBean"> 
          <property name="jobClass"> 
          <value>xj.action.DayDataQuartzTask</value> 
          </property> 
          <property name="jobDataAsMap"> 
          <map> 
          <entry key="jdbc1Service"> 
          <ref bean="jdbc1Service"/> 
          </entry> 
          <entry key="jdbc2Service"> 
          <ref bean="jdbc2Service"/> 
          </entry> 
          </map> 
          </property> 
          </bean> 
          Quartz的org.quartz.Trigger類描述了何時(shí)及以怎樣的頻度運(yùn)行一個(gè)Quartz工作。Spring提供了兩個(gè)觸發(fā)器 SimpleTriggerBean和CronTriggerBean。SimpleTriggerBean與scheduledTimerTasks類 似。指定工作的執(zhí)行頻度,模仿scheduledTimerTasks配置。 
          <!-- 調(diào)度Simple工作 --> 
          <bean id="simpleDayDataJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> 
          <property name="jobDetail"> 
          <ref bean="dayDataJob"/> 
          </property> 
          <property name="startDelay"> 
          <value>1000</value> 
          </property> 
          <property name="repeatInterval"> 
          <value>86400000</value> 
          </property> 
          </bean> 
          <!—調(diào)度cron工作--> 
          <bean id="dayDataJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
          <property name="jobDetail"> 
          <ref bean="dayDataJob"/> 
          </property> 
          <property name="cronExpression"> 
          <value>0 30 2 * * ?</value> 
          </property> 
          </bean> 
          一個(gè)cron表達(dá)式有6個(gè)或7個(gè)由空格分隔的時(shí)間元素。從左至右,這些元素的定義如下:1、秒(0-59);2、分(0-59);3、小時(shí) (0-23);4、月份中的日期(1-31);5、月份(1-12或JAN-DEC);6、星期中的日期(1-7或SUN-SAT);7、年份 (1970-2099)。 
          每一個(gè)元素都可以顯式地規(guī)定一個(gè)值(如6),一個(gè)區(qū)間(如9-12),一個(gè)列表(如9,11,13)或一個(gè)通配符(如*)。“月份中的日期”和“星期中的日期”這兩個(gè)元素互斥,應(yīng)該通過設(shè)置一個(gè)問號(hào)(?)來表明你不想設(shè)置的那個(gè)字段。

          corn表達(dá)式API具體見 

          http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

          我們?cè)诖硕x該任務(wù)在每天凌晨兩點(diǎn)半開始啟動(dòng)。 
          <!—啟動(dòng)工作--> 
          <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
          <property name="triggers"> 
          <list> 
          <ref bean="simpleDayDataJobTrigger"/> 
          <ref bean="dayDataJobTrigger"/> 
          </list> 
          </property> 
          </bean> 
          屬性triggers接受一組觸發(fā)器,在此只裝配包含simpleDayDataJobTrigger bea和dayDataJobTrigger bean的一個(gè)引用列表。

          posted @ 2012-05-30 13:02 askzs 閱讀(2744) | 評(píng)論 (0)編輯 收藏

               摘要: Spring配置文件中關(guān)于事務(wù)配置總是由三個(gè)組成部分,分別是DataSource、TransactionManager和代理機(jī)制這三部分,無論哪種配置方式,一般變化的只是代理機(jī)制這部分。   DataSource、TransactionManager這兩部分只是會(huì)根據(jù)數(shù)據(jù)訪問方式有所變化,比如使用Hibernate進(jìn)行數(shù)據(jù)訪問時(shí),DataSource實(shí)際為SessionFactory,Tran...  閱讀全文
          posted @ 2012-05-30 10:07 askzs 閱讀(369) | 評(píng)論 (0)編輯 收藏

          2012年5月25日 #

          mport java.io.File;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;
          import java.nio.MappedByteBuffer;
          import java.nio.channels.FileChannel;


          public class MbbDemo {
           
           public static  void main(String []args)throws Exception
           {
            File file=new File("d://a.txt");
            FileInputStream fis=new FileInputStream(file);
               FileOutputStream fos=new FileOutputStream("d://acopy.txt");
               FileChannel fChannel=fis.getChannel();
               FileChannel out=fos.getChannel();
               MappedByteBuffer mbb=fChannel.map(FileChannel.MapMode.READ_ONLY, 0,file.length());
               out.write(mbb);
               if(fis!=null)fis.close();
               if(fos!=null)fos.close();
            
            
           }

          }

          posted @ 2012-05-25 14:11 askzs 閱讀(750) | 評(píng)論 (0)編輯 收藏

          2012年5月23日 #

          轉(zhuǎn)載自 http://www.ibm.com/developerworks/cn/java/joy-down/

          斷點(diǎn)續(xù)傳的原理

          其實(shí)斷點(diǎn)續(xù)傳的原理很簡單,就是在 Http 的請(qǐng)求上和一般的下載有所不同而已。
          打個(gè)比方,瀏覽器請(qǐng)求服務(wù)器上的一個(gè)文時(shí),所發(fā)出的請(qǐng)求如下:
          假設(shè)服務(wù)器域名為 wwww.sjtu.edu.cn,文件名為 down.zip。
          GET /down.zip HTTP/1.1
          Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-
          excel, application/msword, application/vnd.ms-powerpoint, */*
          Accept-Language: zh-cn
          Accept-Encoding: gzip, deflate
          User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
          Connection: Keep-Alive

          服務(wù)器收到請(qǐng)求后,按要求尋找請(qǐng)求的文件,提取文件的信息,然后返回給瀏覽器,返回信息如下:

          200
          Content-Length=106786028
          Accept-Ranges=bytes
          Date=Mon, 30 Apr 2001 12:56:11 GMT
          ETag=W/"02ca57e173c11:95b"
          Content-Type=application/octet-stream
          Server=Microsoft-IIS/5.0
          Last-Modified=Mon, 30 Apr 2001 12:56:11 GMT

          所謂斷點(diǎn)續(xù)傳,也就是要從文件已經(jīng)下載的地方開始繼續(xù)下載。所以在客戶端瀏覽器傳給 Web 服務(wù)器的時(shí)候要多加一條信息 -- 從哪里開始。
          下面是用自己編的一個(gè)"瀏覽器"來傳遞請(qǐng)求信息給 Web 服務(wù)器,要求從 2000070 字節(jié)開始。
          GET /down.zip HTTP/1.0
          User-Agent: NetFox
          RANGE: bytes=2000070-
          Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

          仔細(xì)看一下就會(huì)發(fā)現(xiàn)多了一行 RANGE: bytes=2000070-
          這一行的意思就是告訴服務(wù)器 down.zip 這個(gè)文件從 2000070 字節(jié)開始傳,前面的字節(jié)不用傳了。
          服務(wù)器收到這個(gè)請(qǐng)求以后,返回的信息如下:
          206
          Content-Length=106786028
          Content-Range=bytes 2000070-106786027/106786028
          Date=Mon, 30 Apr 2001 12:55:20 GMT
          ETag=W/"02ca57e173c11:95b"
          Content-Type=application/octet-stream
          Server=Microsoft-IIS/5.0
          Last-Modified=Mon, 30 Apr 2001 12:55:20 GMT

          和前面服務(wù)器返回的信息比較一下,就會(huì)發(fā)現(xiàn)增加了一行:
          Content-Range=bytes 2000070-106786027/106786028
          返回的代碼也改為 206 了,而不再是 200 了。

          知道了以上原理,就可以進(jìn)行斷點(diǎn)續(xù)傳的編程了。


          Java 實(shí)現(xiàn)斷點(diǎn)續(xù)傳的關(guān)鍵幾點(diǎn)

          1. (1) 用什么方法實(shí)現(xiàn)提交 RANGE: bytes=2000070-。
            當(dāng)然用最原始的 Socket 是肯定能完成的,不過那樣太費(fèi)事了,其實(shí) Java 的 net 包中提供了這種功能。代碼如下:

            URL url = new URL("http://www.sjtu.edu.cn/down.zip");
            HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();

            // 設(shè)置 User-Agent
            httpConnection.setRequestProperty("User-Agent","NetFox");
            // 設(shè)置斷點(diǎn)續(xù)傳的開始位置
            httpConnection.setRequestProperty("RANGE","bytes=2000070");
            // 獲得輸入流
            InputStream input = httpConnection.getInputStream();

            從輸入流中取出的字節(jié)流就是 down.zip 文件從 2000070 開始的字節(jié)流。大家看,其實(shí)斷點(diǎn)續(xù)傳用 Java 實(shí)現(xiàn)起來還是很簡單的吧。接下來要做的事就是怎么保存獲得的流到文件中去了。

          2. 保存文件采用的方法。
            我采用的是 IO 包中的 RandAccessFile 類。
            操作相當(dāng)簡單,假設(shè)從 2000070 處開始保存文件,代碼如下:
            RandomAccess oSavedFile = new RandomAccessFile("down.zip","rw");
            long nPos = 2000070;
            // 定位文件指針到 nPos 位置
            oSavedFile.seek(nPos);
            byte[] b = new byte[1024];
            int nRead;
            // 從輸入流中讀入字節(jié)流,然后寫到文件中
            while((nRead=input.read(b,0,1024)) > 0)
            {
            oSavedFile.write(b,0,nRead);
            }

          怎么樣,也很簡單吧。接下來要做的就是整合成一個(gè)完整的程序了。包括一系列的線程控制等等。


          斷點(diǎn)續(xù)傳內(nèi)核的實(shí)現(xiàn)

          主要用了 6 個(gè)類,包括一個(gè)測試類。
          SiteFileFetch.java 負(fù)責(zé)整個(gè)文件的抓取,控制內(nèi)部線程 (FileSplitterFetch 類 )。
          FileSplitterFetch.java 負(fù)責(zé)部分文件的抓取。
          FileAccess.java 負(fù)責(zé)文件的存儲(chǔ)。
          SiteInfoBean.java 要抓取的文件的信息,如文件保存的目錄,名字,抓取文件的 URL 等。
          Utility.java 工具類,放一些簡單的方法。
          TestMethod.java 測試類。

          下面是源程序:

          /* 
           /*
           * SiteFileFetch.java 
           */ 
           package NetFox; 
           import java.io.*; 
           import java.net.*; 
           public class SiteFileFetch extends Thread { 
           SiteInfoBean siteInfoBean = null; // 文件信息 Bean 
           long[] nStartPos; // 開始位置
           long[] nEndPos; // 結(jié)束位置
           FileSplitterFetch[] fileSplitterFetch; // 子線程對(duì)象
           long nFileLength; // 文件長度
           boolean bFirst = true; // 是否第一次取文件
           boolean bStop = false; // 停止標(biāo)志
           File tmpFile; // 文件下載的臨時(shí)信息
           DataOutputStream output; // 輸出到文件的輸出流
           public SiteFileFetch(SiteInfoBean bean) throws IOException 
           { 
           siteInfoBean = bean; 
           //tmpFile = File.createTempFile ("zhong","1111",new File(bean.getSFilePath())); 
           tmpFile = new File(bean.getSFilePath()+File.separator + bean.getSFileName()+".info");
           if(tmpFile.exists ()) 
           { 
           bFirst = false; 
           read_nPos(); 
           } 
           else 
           { 
           nStartPos = new long[bean.getNSplitter()]; 
           nEndPos = new long[bean.getNSplitter()]; 
           } 
           } 
           public void run() 
           { 
           // 獲得文件長度
           // 分割文件
           // 實(shí)例 FileSplitterFetch 
           // 啟動(dòng) FileSplitterFetch 線程
           // 等待子線程返回
           try{ 
           if(bFirst) 
           { 
           nFileLength = getFileSize(); 
           if(nFileLength == -1) 
           { 
           System.err.println("File Length is not known!"); 
           } 
           else if(nFileLength == -2) 
           { 
           System.err.println("File is not access!"); 
           } 
           else 
           { 
           for(int i=0;i<nStartPos.length;i++) 
           { 
           nStartPos[i] = (long)(i*(nFileLength/nStartPos.length)); 
           } 
           for(int i=0;i<nEndPos.length-1;i++) 
           { 
           nEndPos[i] = nStartPos[i+1]; 
           } 
           nEndPos[nEndPos.length-1] = nFileLength; 
           } 
           } 
           // 啟動(dòng)子線程
           fileSplitterFetch = new FileSplitterFetch[nStartPos.length]; 
           for(int i=0;i<nStartPos.length;i++) 
           { 
           fileSplitterFetch[i] = new FileSplitterFetch(siteInfoBean.getSSiteURL(), 
           siteInfoBean.getSFilePath() + File.separator + siteInfoBean.getSFileName(), 
           nStartPos[i],nEndPos[i],i); 
           Utility.log("Thread " + i + " , nStartPos = " + nStartPos[i] + ", nEndPos = " 
           + nEndPos[i]); 
           fileSplitterFetch[i].start(); 
           } 
           // fileSplitterFetch[nPos.length-1] = new FileSplitterFetch(siteInfoBean.getSSiteURL(),
           siteInfoBean.getSFilePath() + File.separator 
           + siteInfoBean.getSFileName(),nPos[nPos.length-1],nFileLength,nPos.length-1); 
           // Utility.log("Thread " +(nPos.length-1) + ",nStartPos = "+nPos[nPos.length-1]+",
           nEndPos = " + nFileLength); 
           // fileSplitterFetch[nPos.length-1].start(); 
           // 等待子線程結(jié)束
           //int count = 0; 
           // 是否結(jié)束 while 循環(huán)
           boolean breakWhile = false; 
           while(!bStop) 
           { 
           write_nPos(); 
           Utility.sleep(500); 
           breakWhile = true; 
           for(int i=0;i<nStartPos.length;i++) 
           { 
           if(!fileSplitterFetch[i].bDownOver) 
           { 
           breakWhile = false; 
           break; 
           } 
           } 
           if(breakWhile) 
           break; 
           //count++; 
           //if(count>4) 
           // siteStop(); 
           } 
           System.err.println("文件下載結(jié)束!"); 
           } 
           catch(Exception e){e.printStackTrace ();} 
           } 
           // 獲得文件長度
           public long getFileSize() 
           { 
           int nFileLength = -1; 
           try{ 
           URL url = new URL(siteInfoBean.getSSiteURL()); 
           HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection ();
           httpConnection.setRequestProperty("User-Agent","NetFox"); 
           int responseCode=httpConnection.getResponseCode(); 
           if(responseCode>=400) 
           { 
           processErrorCode(responseCode); 
           return -2; //-2 represent access is error 
           } 
           String sHeader; 
           for(int i=1;;i++) 
           { 
           //DataInputStream in = new DataInputStream(httpConnection.getInputStream ()); 
           //Utility.log(in.readLine()); 
           sHeader=httpConnection.getHeaderFieldKey(i); 
           if(sHeader!=null) 
           { 
           if(sHeader.equals("Content-Length")) 
           { 
           nFileLength = Integer.parseInt(httpConnection.getHeaderField(sHeader)); 
           break; 
           } 
           } 
           else 
           break; 
           } 
           } 
           catch(IOException e){e.printStackTrace ();} 
           catch(Exception e){e.printStackTrace ();} 
           Utility.log(nFileLength); 
           return nFileLength; 
           } 
           // 保存下載信息(文件指針位置)
           private void write_nPos() 
           { 
           try{ 
           output = new DataOutputStream(new FileOutputStream(tmpFile)); 
           output.writeInt(nStartPos.length); 
           for(int i=0;i<nStartPos.length;i++) 
           { 
           // output.writeLong(nPos[i]); 
           output.writeLong(fileSplitterFetch[i].nStartPos); 
           output.writeLong(fileSplitterFetch[i].nEndPos); 
           } 
           output.close(); 
           } 
           catch(IOException e){e.printStackTrace ();} 
           catch(Exception e){e.printStackTrace ();} 
           } 
           // 讀取保存的下載信息(文件指針位置)
           private void read_nPos() 
           { 
           try{ 
           DataInputStream input = new DataInputStream(new FileInputStream(tmpFile)); 
           int nCount = input.readInt(); 
           nStartPos = new long[nCount]; 
           nEndPos = new long[nCount]; 
           for(int i=0;i<nStartPos.length;i++) 
           { 
           nStartPos[i] = input.readLong(); 
           nEndPos[i] = input.readLong(); 
           } 
           input.close(); 
           } 
           catch(IOException e){e.printStackTrace ();} 
           catch(Exception e){e.printStackTrace ();} 
           } 
           private void processErrorCode(int nErrorCode) 
           { 
           System.err.println("Error Code : " + nErrorCode); 
           } 
           // 停止文件下載
           public void siteStop() 
           { 
           bStop = true; 
           for(int i=0;i<nStartPos.length;i++) 
           fileSplitterFetch[i].splitterStop(); 
           } 
           } 
           

           /* 
           **FileSplitterFetch.java 
           */ 
           package NetFox; 
           import java.io.*; 
           import java.net.*; 
           public class FileSplitterFetch extends Thread { 
           String sURL; //File URL 
           long nStartPos; //File Snippet Start Position 
           long nEndPos; //File Snippet End Position 
           int nThreadID; //Thread's ID 
           boolean bDownOver = false; //Downing is over 
           boolean bStop = false; //Stop identical 
           FileAccessI fileAccessI = null; //File Access interface 
           public FileSplitterFetch(String sURL,String sName,long nStart,long nEnd,int id)
           throws IOException 
           { 
           this.sURL = sURL; 
           this.nStartPos = nStart; 
           this.nEndPos = nEnd; 
           nThreadID = id; 
           fileAccessI = new FileAccessI(sName,nStartPos); 
           } 
           public void run() 
           { 
           while(nStartPos < nEndPos && !bStop) 
           { 
           try{ 
           URL url = new URL(sURL); 
           HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection (); 
           httpConnection.setRequestProperty("User-Agent","NetFox"); 
           String sProperty = "bytes="+nStartPos+"-"; 
           httpConnection.setRequestProperty("RANGE",sProperty); 
           Utility.log(sProperty); 
           InputStream input = httpConnection.getInputStream(); 
           //logResponseHead(httpConnection); 
           byte[] b = new byte[1024]; 
           int nRead; 
           while((nRead=input.read(b,0,1024)) > 0 && nStartPos < nEndPos 
           && !bStop) 
           { 
           nStartPos += fileAccessI.write(b,0,nRead); 
           //if(nThreadID == 1) 
           // Utility.log("nStartPos = " + nStartPos + ", nEndPos = " + nEndPos); 
           } 
           Utility.log("Thread " + nThreadID + " is over!"); 
           bDownOver = true; 
           //nPos = fileAccessI.write (b,0,nRead); 
           } 
           catch(Exception e){e.printStackTrace ();} 
           } 
           } 
           // 打印回應(yīng)的頭信息
           public void logResponseHead(HttpURLConnection con) 
           { 
           for(int i=1;;i++) 
           { 
           String header=con.getHeaderFieldKey(i); 
           if(header!=null) 
           //responseHeaders.put(header,httpConnection.getHeaderField(header)); 
           Utility.log(header+" : "+con.getHeaderField(header)); 
           else 
           break; 
           } 
           } 
           public void splitterStop() 
           { 
           bStop = true; 
           } 
           } 
           
           /* 
           **FileAccess.java 
           */ 
           package NetFox; 
           import java.io.*; 
           public class FileAccessI implements Serializable{ 
           RandomAccessFile oSavedFile; 
           long nPos; 
           public FileAccessI() throws IOException 
           { 
           this("",0); 
           } 
           public FileAccessI(String sName,long nPos) throws IOException 
           { 
           oSavedFile = new RandomAccessFile(sName,"rw"); 
           this.nPos = nPos; 
           oSavedFile.seek(nPos); 
           } 
           public synchronized int write(byte[] b,int nStart,int nLen) 
           { 
           int n = -1; 
           try{ 
           oSavedFile.write(b,nStart,nLen); 
           n = nLen; 
           } 
           catch(IOException e) 
           { 
           e.printStackTrace (); 
           } 
           return n; 
           } 
           } 
           
           /* 
           **SiteInfoBean.java 
           */ 
           package NetFox; 
           public class SiteInfoBean { 
           private String sSiteURL; //Site's URL 
           private String sFilePath; //Saved File's Path 
           private String sFileName; //Saved File's Name 
           private int nSplitter; //Count of Splited Downloading File 
           public SiteInfoBean() 
           { 
           //default value of nSplitter is 5 
           this("","","",5); 
           } 
           public SiteInfoBean(String sURL,String sPath,String sName,int nSpiltter)
           { 
           sSiteURL= sURL; 
           sFilePath = sPath; 
           sFileName = sName; 
           this.nSplitter = nSpiltter; 
           } 
           public String getSSiteURL() 
           { 
           return sSiteURL; 
           } 
           public void setSSiteURL(String value) 
           { 
           sSiteURL = value; 
           } 
           public String getSFilePath() 
           { 
           return sFilePath; 
           } 
           public void setSFilePath(String value) 
           { 
           sFilePath = value; 
           } 
           public String getSFileName() 
           { 
           return sFileName; 
           } 
           public void setSFileName(String value) 
           { 
           sFileName = value; 
           } 
           public int getNSplitter() 
           { 
           return nSplitter; 
           } 
           public void setNSplitter(int nCount) 
           { 
           nSplitter = nCount; 
           } 
           } 
           
           /* 
           **Utility.java 
           */ 
           package NetFox; 
           public class Utility { 
           public Utility() 
           { 
           } 
           public static void sleep(int nSecond) 
           { 
           try{ 
           Thread.sleep(nSecond); 
           } 
           catch(Exception e) 
           { 
           e.printStackTrace (); 
           } 
           } 
           public static void log(String sMsg) 
           { 
           System.err.println(sMsg); 
           } 
           public static void log(int sMsg) 
           { 
           System.err.println(sMsg); 
           } 
           } 
           
           /* 
           **TestMethod.java 
           */ 
           package NetFox; 
           public class TestMethod { 
           public TestMethod() 
           { ///xx/weblogic60b2_win.exe 
           try{ 
           SiteInfoBean bean = new SiteInfoBean("http://localhost/xx/weblogic60b2_win.exe",
               "L:\\temp","weblogic60b2_win.exe",5); 
           //SiteInfoBean bean = new SiteInfoBean("http://localhost:8080/down.zip","L:\\temp",
               "weblogic60b2_win.exe",5); 
           SiteFileFetch fileFetch = new SiteFileFetch(bean); 
           fileFetch.start(); 
           } 
           catch(Exception e){e.printStackTrace ();} 
           } 
           public static void main(String[] args) 
           { 
           new TestMethod(); 
           } 
           }
          


          posted @ 2012-05-23 15:13 askzs 閱讀(688) | 評(píng)論 (0)編輯 收藏

          2010年7月20日 #


          如圖:



          下載地址:http://www.aygfsteel.com/Files/f6k66ve/qzoneedit-64.rar

          有好多朋友說在chrome瀏覽器下不能使用,看了下代碼,js中用到parent,在ie下js支持的很好,但是chrome對(duì)parnet支持的并不是很好,就是在本地測試時(shí),不能顯示,也不能使用,但是要把程序放到服務(wù)器上,就能很好的支持,能很好的使用,還有一點(diǎn)要注意,如果放到本機(jī)的服務(wù)器上,不要用localhost訪問,要用127.0.0.1訪問,我把程序放到tomcat下,直接訪問http://localhost:8080/qw/ 則不能正確使用,但是http://127.0.0.1:8080/qw/ 這個(gè)地址能很好的訪問,我就不截圖了,總之一句話,這個(gè)編輯器是能在chrome下使用的,程序需要web服務(wù)器的支持

          posted @ 2010-07-20 16:49 askzs 閱讀(2646) | 評(píng)論 (7)編輯 收藏

          僅列出標(biāo)題  下一頁
          我要啦免费统计
          主站蜘蛛池模板: 鄂托克前旗| 镇雄县| 江北区| 锡林浩特市| 宁德市| 临潭县| 加查县| 承德县| 准格尔旗| 富民县| 杭州市| 嘉兴市| 汕头市| 东明县| 达孜县| 德保县| 西林县| 乐昌市| 建湖县| 阿尔山市| 安泽县| 东丽区| 宾川县| 白玉县| 砀山县| 神木县| 北流市| 沈阳市| 秦安县| 兴宁市| 容城县| 绥宁县| 大宁县| 商河县| 错那县| 皮山县| 巴林左旗| 临海市| 江孜县| 黄龙县| 大厂|