<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    陌上花開

    遇高山,我御風而翔,逢江河,我凌波微波

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::

    2010年4月1日 #

    標準javascript 是內含支持hash關聯數組,經查找資料并測試,有關標準javascript內含的hash關聯數組操作備忘如下

    1。Hash關聯數組定義

    // 定義空數組
    myhash = { }

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

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

    2。向Hash關聯數組添加鍵值

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

    3。刪除Hash關聯數組已有鍵值

    // 刪除一個鍵 newkey ,同時,該鍵值對應的 newval 也就消失了
    delete myhash[”newkey”];

    4。遍歷Hash關聯數組

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

    5。Hash關聯數組簡易使用示例

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

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

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

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

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

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

     

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

      什么是Uploadify

      Uploadify是JQuery的一個上傳插件,支持多文件上傳,實現的效果非常不錯,帶進度顯示。

      官網提供的是PHP的DEMO,在這里我詳細介紹在Asp.net下的使用.

      下載

        官方下載

        官方文檔

        官方演示

      如何使用

      1 創建Web項目,命名為JQueryUploadDemo,從官網上下載最新的版本解壓后添加到項目中

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

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

      進行完上面三步后項目的基本結構如下圖:

      

      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); 
           
    //下面這句代碼缺少的話,上傳成功后上傳隊列的顯示不會自動消失
           context.Response.Write("1"); 
        }  
       
    else 
        {  
            context.Response.Write(
    "0");  
        } 
    }

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

    6 運行后效果如下圖:

      

      7 選擇了兩個文件后,點擊上傳,就可以看到UploadFile文件夾中會增加這兩個文件。

      

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

     

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

      

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

      

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

    onInit : 做一些初始化的工作

    onSelect :選擇文件時觸發,該函數有三個參數

    • event:事件對象。
    • queueID:文件的唯一標識,由6為隨機字符組成。
    • fileObj:選擇的文件對象,有name、size、creationDate、modificationDate、type 5個屬性。

    代碼如下:

      

    $(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(
    "唯一標識:" + queueId + "\r\n" +
                     
    "文件名:" + fileObj.name + "\r\n" +
                     
    "文件大?。?/span>" + fileObj.size + "\r\n" +
                     
    "創建時間:" + fileObj.creationDate + "\r\n" +
                     
    "最后修改時間:" + fileObj.modificationDate + "\r\n" +
                     
    "文件類型:" + fileObj.type
                );

            }
        });
    }); 

     


    當選擇一個文件后彈出的消息如下圖:

    onSelectOnce :在單文件或多文件上傳時,選擇文件時觸發。該函數有兩個參數event,data,data對象有以下幾個屬性:

    fileCount:選擇文件的總數。
    filesSelected:同時選擇文件的個數,如果一次選擇了3個文件該屬性值為3。
    filesReplaced:如果文件隊列中已經存在A和B兩個文件,再次選擇文件時又選擇了A和B,該屬性值為2。
    allBytesTotal:所有選擇的文件的總大小。
     

    onCancel : 當點擊文件隊列中文件的關閉按鈕或點擊取消上傳時觸發。該函數有event、queueId、fileObj、data四個參數,前三個參數同onSelect 中的三個參數,data對象有兩個屬性fileCount和allBytesTotal。

    fileCount:取消一個文件后,文件隊列中剩余文件的個數。
    allBytesTotal:取消一個文件后,文件隊列中剩余文件的大小。
     

    onClearQueue :當調用函數fileUploadClearQueue時觸發。有event和data兩個參數,同onCancel 中的兩個對應參數。

    onQueueFull :當設置了queueSizeLimit并且選擇的文件個數超出了queueSizeLimit的值時觸發。該函數有兩個參數event和queueSizeLimit。

    onError :當上傳過程中發生錯誤時觸發。該函數有event、queueId、fileObj、errorObj四個參數,其中前三個參數同上,errorObj對象有type和info兩個屬性。

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

    onOpen :點擊上傳時觸發,如果auto設置為true則是選擇文件時觸發,如果有多個文件上傳則遍歷整個文件隊列。該函數有event、queueId、fileObj三個參數,參數的解釋同上。

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

    percentage:當前完成的百分比
    bytesLoaded:當前上傳的大小
    allBytesLoaded:文件隊列中已經上傳完的大小
    speed:上傳速率 kb/s
     

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

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

     

    onAllComplete:文件隊列中所有的文件上傳完成后觸發。該函數有event和data兩個參數,data有四個屬性,分別為:

    filesUploaded :上傳的所有文件個數。
    errors :出現錯誤的個數。
    allBytesLoaded :所有上傳文件的總大小。
    speed :平均上傳速率 kb/s
     

    相關函數介紹

    在上面的例子中已經用了uploadifyUpload和uploadifyClearQueue兩個函數,除此之外還有幾個函數:

    uploadifySettings:可以動態修改上面介紹的那些key值,如下面代碼

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

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

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

      uploadifyCancel:該函數接受一個queueID作為參數,可以取消文件隊列中指定queueID的文件。

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

     

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

      

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

    暫時還沒有遇到其它問題,后續發現問題再加。

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

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

    特性:

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

    下載

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

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

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


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

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

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

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

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

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

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

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

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

    1. Java Timer調度器 
    首先定義一個定時器任務,繼承java.util.TimerTask類實現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("日凍結轉接任務開始時間:"+df.format(Calendar.getInstance().getTime())); 
    System.out.println("日凍結轉接任務結束時間:"+df.format(Calendar.getInstance().getTime())); 


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


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


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

    2.Quartz調度器 
    Quartz調度器不僅可以定義每隔多少毫秒執行一個工作,還允許你調度一個工作在某個特定的時間或日期執行。 
    首先創建一個工作,繼承QuartzJobBean類實現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("日凍結轉接任務開始時間:"+df.format(Calendar.getInstance().getTime())); 
    System.out.println("日凍結轉接任務結束時間:"+df.format(Calendar.getInstance().getTime())); 


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


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




    在Spring配置文件中按照以下方式聲明這個工作: 
    <!-- 定時啟動任務 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類描述了何時及以怎樣的頻度運行一個Quartz工作。Spring提供了兩個觸發器 SimpleTriggerBean和CronTriggerBean。SimpleTriggerBean與scheduledTimerTasks類 似。指定工作的執行頻度,模仿scheduledTimerTasks配置。 
    <!-- 調度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> 
    <!—調度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> 
    一個cron表達式有6個或7個由空格分隔的時間元素。從左至右,這些元素的定義如下:1、秒(0-59);2、分(0-59);3、小時 (0-23);4、月份中的日期(1-31);5、月份(1-12或JAN-DEC);6、星期中的日期(1-7或SUN-SAT);7、年份 (1970-2099)。 
    每一個元素都可以顯式地規定一個值(如6),一個區間(如9-12),一個列表(如9,11,13)或一個通配符(如*)。“月份中的日期”和“星期中的日期”這兩個元素互斥,應該通過設置一個問號(?)來表明你不想設置的那個字段。

    corn表達式API具體見 

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

    我們在此定義該任務在每天凌晨兩點半開始啟動。 
    <!—啟動工作--> 
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    <property name="triggers"> 
    <list> 
    <ref bean="simpleDayDataJobTrigger"/> 
    <ref bean="dayDataJobTrigger"/> 
    </list> 
    </property> 
    </bean> 
    屬性triggers接受一組觸發器,在此只裝配包含simpleDayDataJobTrigger bea和dayDataJobTrigger bean的一個引用列表。

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

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

    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 閱讀(742) | 評論 (0)編輯 收藏

    轉載自 http://www.ibm.com/developerworks/cn/java/joy-down/

    斷點續傳的原理

    其實斷點續傳的原理很簡單,就是在 Http 的請求上和一般的下載有所不同而已。
    打個比方,瀏覽器請求服務器上的一個文時,所發出的請求如下:
    假設服務器域名為 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

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

    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

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

    仔細看一下就會發現多了一行 RANGE: bytes=2000070-
    這一行的意思就是告訴服務器 down.zip 這個文件從 2000070 字節開始傳,前面的字節不用傳了。
    服務器收到這個請求以后,返回的信息如下:
    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

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

    知道了以上原理,就可以進行斷點續傳的編程了。


    Java 實現斷點續傳的關鍵幾點

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

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

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

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

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

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


    斷點續傳內核的實現

    主要用了 6 個類,包括一個測試類。
    SiteFileFetch.java 負責整個文件的抓取,控制內部線程 (FileSplitterFetch 類 )。
    FileSplitterFetch.java 負責部分文件的抓取。
    FileAccess.java 負責文件的存儲。
    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; // 結束位置
     FileSplitterFetch[] fileSplitterFetch; // 子線程對象
     long nFileLength; // 文件長度
     boolean bFirst = true; // 是否第一次取文件
     boolean bStop = false; // 停止標志
     File tmpFile; // 文件下載的臨時信息
     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() 
     { 
     // 獲得文件長度
     // 分割文件
     // 實例 FileSplitterFetch 
     // 啟動 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; 
     } 
     } 
     // 啟動子線程
     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(); 
     // 等待子線程結束
     //int count = 0; 
     // 是否結束 while 循環
     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("文件下載結束!"); 
     } 
     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 ();} 
     } 
     } 
     // 打印回應的頭信息
     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 閱讀(681) | 評論 (0)編輯 收藏


    如圖:



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

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

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

    北冥有魚,其名為鯤。鯤之大,不知其幾千里也;化而為鳥,其名為鵬。鵬之背,不知其幾千里也;怒而飛,其翼若垂天之云 。是鳥也,海運則將徙于南冥。南冥者,天池也?!洱R諧》者,志怪者也 ?!吨C》之言曰:“鵬之徙于南冥也,水擊三千里,摶扶搖而上者九萬里,去以六月息者也。”野馬也,塵埃也,生物之以息相吹也。天之蒼蒼,其正色邪?其遠而無所至極邪?其視下也,亦若是則已矣。且夫水之積也不厚,則其負大舟也無力。覆杯水于坳堂之上,則芥為之舟,置杯焉則膠,水淺而舟大也。風之積也不厚,則其負大翼也無力。故九萬里,則風斯在下矣,而后乃今培風;背負青天,而莫之夭閼者,而后乃今將圖南。蜩與學鳩笑之曰:“我決起而飛 ,搶榆枋而止,時則不至,而控于地而已矣,奚以之九萬里而南為?”適莽蒼者,三餐而反,腹猶果然;適百里者,宿舂糧;適千里者,三月聚糧。之二蟲又何知!小知不及大知,小年不及大年。奚以知其然也?朝菌不知晦朔,蟪蛄不知春秋,此小年也。楚之南有冥靈者,以五百歲為春,五百歲為秋;上古有大椿者,以八千歲為春,八千歲為秋,此大年也。而彭祖乃今以久特聞,眾人匹之,不亦悲乎?  湯之問棘也是已:“窮發之北,有冥海者,天池也。有魚焉,其廣數千里,未有知其修者,其名為鯤。有鳥焉,其名為鵬,背若泰山,翼若垂天之云,摶扶搖羊角而上者九萬里,絕云氣,負青天,然后圖南,且適南冥也。斥鴳笑之曰:‘彼且奚適也?我騰躍而上,不過數仞而下,翱翔蓬蒿之間,此亦飛之至也。而彼且奚適也?’”此小大之辯也。故夫知效一官、行比一鄉 、德合一君、而征一國者,其自視也,亦若此矣。而宋榮子猶然笑之。且舉世譽之而不加勸,舉世非之而不加沮,定乎內外之分,辯乎榮辱之境,斯已矣。彼其于世,未數數然也。雖然,猶有未樹也。夫列子御風而行,泠然善也,旬有五日而后反。彼于致福者,未數數然也。此雖免乎行,猶有所待者也。若夫乘天地之正,而御六氣之辯,以游無窮者,彼且惡乎待哉?故曰:至人無己,神人無功,圣人無名.
    posted @ 2010-06-08 09:15 askzs 閱讀(179) | 評論 (0)編輯 收藏

    Ajax+Flash多文件上傳是一個開源的上傳組件,名稱是FancyUpload,其官方網址是:http://digitarald.de/project/fancyupload/。這個組件僅僅是客戶端的應用組件,即與任何服務器端的技術沒有關系,服務器端可以采用任何后臺技術(如JSP、Servlet、ASP等)。應用該組件提供 給我們的最大的好處有如下幾點(個人認為,呵呵):

    1          僅是客戶端的應用組件,服務器端可以采用任何后臺技術 
    2 可以同時選擇多個文件進行上傳;
    3         以隊列的形式排列要上傳的文件和其相關信息(如名稱、大小等);
    4        
    可以設置要上傳的文件個數、文件類型和文件大小;
    5        
    有上傳進度顯示, 直觀,實用);
    6      
    上傳的過程中可以隨時取消要上傳的文件;
    7      
    平臺獨立性,由于使用flash和 成熟的AJAX框架(mootools)可以避免對特定瀏覽器和服務器依賴!
    8       
    使用簡單,文件體積小!
    9
      表單無須設置enctype="multipart/form-data"


    posted @ 2010-06-07 15:46 askzs 閱讀(1172) | 評論 (1)編輯 收藏

    轉載于http://blog.csdn.net/sunyujia/archive/2008/06/15/2549347.aspx

    <html>   
    <head>   
     
    <title>Add Files</title>   
     
    <style>   
     
    a.addfile {   
     
    background-image:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);   
     
    background-repeat:no-repeat;   
     
    background-position:-823px -17px;   
     
    display:block;   
     
    float:left;   
     
    height:20px;   
     
    margin-top:-1px;   
     
    position:relative;   
     
    text-decoration:none;   
     
    top:0pt;   
     
    width:80px;   
     
    }   
     
     
     
    input.addfile {   
     
    /*left:-18px;*/  
     
    }   
     
     
     
    input.addfile {   
     
    cursor:pointer !important;   
     
    height:18px;   
     
    left:-13px;   
     
    filter:alpha(opacity=0);    
     
    position:absolute;   
     
    top:5px;   
     
    width:1px;   
     
    z-index: -1;   
     
    }   
     
    </style>   
     
     
     
    <script type="text/javascript">   
     
     
     
    function MultiSelector(list_target, max)   
     
    {   
     
        // Where to write the list   
     
        this.list_target = list_target;   
     
        // How many elements?   
     
        this.count = 0;   
     
        // How many elements?   
     
        this.id = 0;   
     
        // Is there a maximum?   
     
        if (max)   
     
        {   
     
            this.max = max;   
     
        }    
     
        else    
     
        {   
     
            this.max = -1;   
     
        };   
     
     
     
        /**  
     
         * Add a new file input element  
     
         */  
     
        this.addElement = function(element)   
     
        {   
     
            // Make sure it's a file input element   
     
            if (element.tagName == 'INPUT' && element.type == 'file')   
     
            {   
     
                // Element name -- what number am I?   
     
                element.name = 'file_' + this.id++;   
     
     
     
                // Add reference to this object   
     
                element.multi_selector = this;   
     
     
     
                // What to do when a file is selected   
     
                element.onchange = function()   
     
                {   
     
                    // New file input   
     
                    var new_element = document.createElement('input');   
     
                    new_element.type = 'file';   
     
                    new_element.size = 1;   
     
                    new_element.className = "addfile";   
     
     
     
                    // Add new element   
     
                    this.parentNode.insertBefore(new_element, this);   
     
     
     
                    // Apply 'update' to element   
     
                    this.multi_selector.addElement(new_element);   
     
     
     
                    // Update list   
     
                    this.multi_selector.addListRow(this);   
     
     
     
                    // Hide this: we can't use display:none because Safari doesn't like it   
     
                    this.style.position = 'absolute';   
     
                    this.style.left = '-1000px';   
     
                };   
     
     
     
     
     
                // If we've reached maximum number, disable input element   
     
                if (this.max != -1 && this.count >= this.max)   
     
                {   
     
                    element.disabled = true;   
     
                };   
     
     
     
                // File element counter   
     
                this.count++;   
     
                // Most recent element   
     
                this.current_element = element;   
     
            }    
     
            else    
     
            {   
     
                // This can only be applied to file input elements!   
     
                alert('Error: not a file input element');   
     
            };   
     
        };   
     
     
     
     
     
        /**  
     
         * Add a new row to the list of files  
     
         */  
     
        this.addListRow = function(element)   
     
        {   
     
            // Row div   
     
            var new_row = document.createElement('div');   
     
     
     
            // Delete button   
     
            var new_row_button = document.createElement('input');   
     
            new_row_button.type = 'button';   
     
            new_row_button.value = 'Delete';   
     
     
     
            // References   
     
            new_row.element = element;   
     
     
     
            // Delete function   
     
            new_row_button.onclick = function()   
     
            {   
     
                // Remove element from form   
     
                this.parentNode.element.parentNode.removeChild(this.parentNode.element);   
     
     
     
                // Remove this row from the list   
     
                this.parentNode.parentNode.removeChild(this.parentNode);   
     
     
     
                // Decrement counter   
     
                this.parentNode.element.multi_selector.count--;   
     
     
     
                // Re-enable input element (if it's disabled)   
     
                this.parentNode.element.multi_selector.current_element.disabled = false;   
     
     
     
                // Appease Safari   
     
                // without it Safari wants to reload the browser window   
     
                // which nixes your already queued uploads   
     
                return false;   
     
            };   
     
     
     
            // Set row value   
     
            new_row.innerHTML = element.value + " ";   
     
     
     
            // Add button   
     
            new_row.appendChild(new_row_button);   
     
     
     
            // Add it to the list   
     
            this.list_target.appendChild(new_row);   
     
        };   
     
    };   
     
    </script>   
     
    </head>   
     
     
     
    <body>   
     
     
     
    <!-- This is the form -->   
     
    <form enctype="multipart/form-data" action="http://127.0.0.1:8080/zzgh/cx/upload.jsp" method="post">   
     
    <!-- The file element -- NOTE: it has an ID -->   
     
    <a href="javascript:void(1==1);" class="addfile" style="cursor: default;" hidefocus="true">   
     
    <input id="my_file_element" class="addfile" type="file" name="file_1" size="1" title="點擊選擇附件">   
     
    </a>   
     
    <input type="submit" value="上 傳">   
     
    </form>   
     
     
     
    Files:   
     
    <!-- This is where the output will appear -->   
     
    <div id="files_list" style="padding:5px;border:1px;border-style:solid;border-color:#0000ff;height:100px;width:600px;"></div>   
     
    <script>   
     
    <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->   
     
    var multi_selector = new MultiSelector(document.getElementById('files_list'), 100);   
     
    <!-- Pass in the file element -->   
     
    multi_selector.addElement(document.getElementById('my_file_element'));   
     
    </script>   
    </body>   
     
    </html> 


    效果圖如下:



    posted @ 2010-06-04 17:12 askzs 閱讀(436) | 評論 (0)編輯 收藏

    一,先新建一個excel文件,調整格式(就是你所想要顯示的格式),
    二,把剛才新建的excel文件令存為.html(demo.html)文件,
    三,新建一個jsp頁面, 在該JSP頁面頭部設置response的ContentType為Excel格式
    <% response.setContentType("application/vnd.ms-excel;charset=GBK"); %>
    然后設置網頁資料是以excel報表以線上瀏覽方式呈現或者是下載的方式呈現
    <%
    / /這行設定傳送到前端瀏覽器時的檔名為test1.xls  就是靠這一行,讓前端瀏覽器以為接收到一個excel檔 
     //將網頁資料以excel報表以線上瀏覽方式呈現
    response.setHeader("Content-disposition","inline; filename=test1.xls");
       //將網頁資料以下載的方式
    response.setHeader("Content-disposition","attachment; filename=test2.xls");
    %>
    然后把 demo.html的源代碼粘貼在jsp頁面,如下

    <%@ page contentType="text/html; charset=GBK" %>
    <% response.setContentType("application/vnd.ms-excel;charset=GBK");
    response.setHeader("Content-disposition","attachment; filename=test2.xls");

    %>
    <!--以下為保持成html頁面的excel的內容 demo.html頁面-->
    <html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">

    <head>
    <meta http-equiv=Content-Type content="text/html; charset=gb2312">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 11">
    <link rel=File-List href="qwe.files/filelist.xml">
    <link rel=Edit-Time-Data href="qwe.files/editdata.mso">
    <link rel=OLE-Object-Data href="qwe.files/oledata.mso">
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
      <o:Created>1996-12-17T01:32:42Z</o:Created>
      <o:LastSaved>2010-05-12T13:59:04Z</o:LastSaved>
      <o:Version>11.9999</o:Version>
     </o:DocumentProperties>
     <o:OfficeDocumentSettings>
      <o:RemovePersonalInformation/>
     </o:OfficeDocumentSettings>
    </xml><![endif]-->
    <style>
    <!--table
     {mso-displayed-decimal-separator:"\.";
     mso-displayed-thousand-separator:"\,";}
    @page
     {margin:1.0in .75in 1.0in .75in;
     mso-header-margin:.5in;
     mso-footer-margin:.5in;}
    tr
     {mso-height-source:auto;
     mso-ruby-visibility:none;}
    col
     {mso-width-source:auto;
     mso-ruby-visibility:none;}
    br
     {mso-data-placement:same-cell;}
    .style0
     {mso-number-format:General;
     text-align:general;
     vertical-align:bottom;
     white-space:nowrap;
     mso-rotate:0;
     mso-background-source:auto;
     mso-pattern:auto;
     color:windowtext;
     font-size:12.0pt;
     font-weight:400;
     font-style:normal;
     text-decoration:none;
     font-family:宋體;
     mso-generic-font-family:auto;
     mso-font-charset:134;
     border:none;
     mso-protection:locked visible;
     mso-style-name:常規;
     mso-style-id:0;}
    td
     {mso-style-parent:style0;
     padding-top:1px;
     padding-right:1px;
     padding-left:1px;
     mso-ignore:padding;
     color:windowtext;
     font-size:12.0pt;
     font-weight:400;
     font-style:normal;
     text-decoration:none;
     font-family:宋體;
     mso-generic-font-family:auto;
     mso-font-charset:134;
     mso-number-format:General;
     text-align:general;
     vertical-align:bottom;
     border:none;
     mso-background-source:auto;
     mso-pattern:auto;
     mso-protection:locked visible;
     white-space:nowrap;
     mso-rotate:0;}
    ruby
     {ruby-align:left;}
    rt
     {color:windowtext;
     font-size:9.0pt;
     font-weight:400;
     font-style:normal;
     text-decoration:none;
     font-family:宋體;
     mso-generic-font-family:auto;
     mso-font-charset:134;
     mso-char-type:none;
     display:none;}
    -->
    </style>
    <!--[if gte mso 9]><xml>
     <x:ExcelWorkbook>
      <x:ExcelWorksheets>
       <x:ExcelWorksheet>
        <x:Name>Sheet1</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:CodeName>Sheet1</x:CodeName>
         <x:Selected/>
         <x:Panes>
          <x:Pane>
           <x:Number>3</x:Number>
           <x:ActiveCol>1</x:ActiveCol>
          </x:Pane>
         </x:Panes>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>Sheet2</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:CodeName>Sheet2</x:CodeName>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
       <x:ExcelWorksheet>
        <x:Name>Sheet3</x:Name>
        <x:WorksheetOptions>
         <x:DefaultRowHeight>285</x:DefaultRowHeight>
         <x:CodeName>Sheet3</x:CodeName>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
      </x:ExcelWorksheets>
      <x:WindowHeight>4530</x:WindowHeight>
      <x:WindowWidth>8505</x:WindowWidth>
      <x:WindowTopX>480</x:WindowTopX>
      <x:WindowTopY>120</x:WindowTopY>
      <x:AcceptLabelsInFormulas/>
      <x:ProtectStructure>False</x:ProtectStructure>
      <x:ProtectWindows>False</x:ProtectWindows>
     </x:ExcelWorkbook>
    </xml><![endif]-->
    </head>

    <body link=blue vlink=purple>

    <table x:str border=0 cellpadding=0 cellspacing=0 width=288 style='border-collapse:
     collapse;table-layout:fixed;width:216pt'>
     <col width=72 span=4 style='width:54pt'>
     <tr height=19 style='height:14.25pt'>
      <td height=19 width=72 style='height:14.25pt;width:54pt'>全球</td>
      <td width=72 style='width:54pt'>問問</td>
      <td width=72 style='width:54pt'>ee</td>
      <td width=72 style='width:54pt'>rr</td>
     </tr>
     <tr height=19 style='height:14.25pt'>
      <td height=19 style='height:14.25pt'>暗暗</td>
      <td>ss</td>
      <td>dd</td>
      <td>ff</td>
     </tr>
     <![if supportMisalignedColumns]>
     <tr height=0 style='display:none'>
      <td width=72 style='width:54pt'></td>
      <td width=72 style='width:54pt'></td>
      <td width=72 style='width:54pt'></td>
      <td width=72 style='width:54pt'></td>
     </tr>
     <![endif]>
    </table>

    </body>

    </html>


    中文問題:
    查看源代碼時發現JSP文件中寫死的中文為亂碼,則在JSP文件頭部添加一行
    <%@ page contentType="text/html; charset=gb2312" %>
    查看源代碼時發現文字為中文,但是用Excel打開為亂碼則在<html>與<head>中加入
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">

    在jsp頁面中,要在excel中顯示的內容可以從數據庫中讀取,在此就不做詳細的介紹了

    posted @ 2010-05-12 22:06 askzs 閱讀(4740) | 評論 (0)編輯 收藏

     在DHTML開發中,微軟在其DOM中為每個元素實現了一個fireEvent方法。我們知道HTML的事件onXXX可以由系統(IE環境)來管理和觸發,也可以直接執行事件的handler,比如onclick,如果被賦予事件處理函數,我們可以用element.onclick()來執行事件處理函數。那么fireEvent用來干嘛呢?

        在MSDN中fireEvent的描述很簡單:Fires a specified event on the object.
        bFired = object.fireEvent(sEvent [, oEventObject])

        并且MSDN給出了一個使用fireEvent的示例:
    <HTML>
        
    <HEAD>
            
    <SCRIPT>
            
    function fnFireEvents()
            
    {
                div.innerText 
    = "The cursor has moved over me!";
                btn.fireEvent(
    "onclick");
            }

            
    </SCRIPT>
        
    </HEAD>
        
    <BODY>
            
    <h1>Using the fireEvent method</h1>
            By moving the cursor over the DIV below, the button is clicked.
            
    <DIV ID="div" onmouseover="fnFireEvents();">
                Mouse over this!
            
    </DIV>
            
    <BUTTON ID="btn" ONCLICK="this.innerText='I have been clicked!'">Button</BUTTON>
        
    </BODY>
    </HTML>

        這個示例非常的簡單,也完全說明了fireEvent的用法。不過這個示例有一點誤導我們,從而讓我們不容易發現frieEvent更有價值的使用方法。由于button的onclick事件被賦予語句:this.innerText = 'I have been clicked!',這里很容易誤導我們,fireEvent產生的是執行了btn.onclick()的效果。嗯,確實是這個效果,但是意義卻完全不同,btn.onclick()只是一個函數調用,它的執行必須依賴于用戶對其賦值,否則btn.onclick為null,是不能執行btn.onclick()的。而fireEvent('onclick')的效果,"等同于"鼠標在button元素上進行了點擊。

        由于IE的事件處理是bubble up方式,fireEvent(sEvent)就顯得更加的有意義了,如果我們在一個table元素<table>中監聽事件,比如onclick,當點擊不同的td做出不同的響應時。如果使用程序來模擬,只能使用fireEvent這種方式,示例如下:

    <table border="1" onclick="alert(event.srcElement.innerText);">
        
    <tr>
            
    <td id="abc">abc</td>
            
    <td id="def">def</td>
        
    </tr>
    </table>
    <button onclick="abc.fireEvent('onclick')">
        abc
    </button>
    <button onclick="def.fireEvent('onclick')">
        def
    </button>

        使用abc.onclick()和def.onclick()將得到"Object doesn't support this property or method"異常。

       
    abc def

         

        知道了fireEvent的用法,那么我們用它來做什么呢?在開發具有復雜事件處理動作組件時。有時我們需要從程序中去觸發一個本身因該鼠標或鍵盤觸發的事件,比如在TreeView控件中,我們一般是使用鼠標點擊來Expand&Collapse一個結點,如果我們要用程序代碼來實現這個操作怎么辦呢?當然直接執行事件處理函數是可以的,不過如果事件處理函數依賴于event變量中的狀態值,那么就必須使用fireEvent方法。

        原來我曾經說過,因該把事件處理的函數封裝起來,便于直接調用。比如上面說到的TreeView節點的Expand和Collapse,我在TreeView控件中都是把它們封裝成兩個函數Expand和Collapse,在節點被點擊時,執行:
     OpIcon.onclick = function()
     {
         
    var objNode = this.Object;
         
    if ( objNode.m_IsExpanded )
             objNode.Collapse();
        
    else
             objNode.Expaned();
     }

        這樣一來,在程序中控制Expand和Collapse也就是分別執行函數而已。不過后來發現既然DOM中有fireEvent方法,似乎我在"
    轉載:
    http://www.cnblogs.com/birdshome/archive/2005/04/07/128182.html
    posted @ 2010-04-01 22:19 askzs 閱讀(389) | 評論 (0)編輯 收藏

    select 或text的onchange事件需要手動(通過鍵盤輸入)改變select或text的值才能觸發,如果在js中給select或text賦值,則無法觸發onchang事件,
    例如,在頁面加載完成以后,需要觸發一個onChange事件,在js中用document.getElementById("se").value="ttt";直接給select或text賦值是不行的,要想實現手動觸發onchange事件,需要在js給select賦值后,加入下面的語句,(假設select的id為sel)
    document.getElementById("sel").fireEvent('onchange') 來實現,
    例子:
         <html><body>
        
        
    <select id="sel" name="test" onchange="demo()">
          
    <option value="1" selected>測試一</option>
      
    <option value="2">測試二</option>
      
    <option value="3">測試三</option>
      
    <option value="4">測試四</option>
       
    </select>
     
    <input id="tex" type="text" name="text1"  id="text1">
       
      
    <script>
      
      document.getElementById(
    "sel").value="3";
      document.getElementById(
    "sel").fireEvent("onchange");
      
    function demo()
      {
       
    var d=document.getElementById("sel").value;
       document.getElementById(
    "tex").value=d;
       
    //alert(d);
      
      }
      
    </script>
        
    </body></html>

    上面的代碼產生的效果就相當于鼠標在select元素上進行了選擇,模仿出了select的onchange效果

    posted @ 2010-04-01 22:15 askzs 閱讀(39983) | 評論 (10)編輯 收藏

    我要啦免费统计
    主站蜘蛛池模板: 亚洲免费网站在线观看| 91精品国产免费入口| 亚洲国产午夜电影在线入口| 亚洲日韩在线中文字幕第一页| av无码免费一区二区三区| 精品亚洲永久免费精品| 一级女性全黄久久生活片免费 | 亚洲日产乱码一二三区别| 亚洲av丰满熟妇在线播放| 亚洲美日韩Av中文字幕无码久久久妻妇| 免费观看的a级毛片的网站| 无码国产精品一区二区免费式直播| 全免费a级毛片免费看| 国产特黄特色的大片观看免费视频 | 亚洲av无码专区在线电影| 亚洲毛片一级带毛片基地| 亚洲国产成人一区二区精品区| 亚洲国产精品无码久久青草| 免费看www视频| 免费观看男人免费桶女人视频 | 亚洲伊人久久大香线蕉啊| 亚洲国产天堂久久综合网站 | 久久99精品免费视频| 东北美女野外bbwbbw免费| 一区二区3区免费视频| 免费国产va视频永久在线观看| 亚洲爆乳精品无码一区二区| 亚洲人成人网站18禁| 亚洲综合av一区二区三区不卡 | **真实毛片免费观看| 久久青草免费91观看| 亚洲免费视频在线观看| 免费一区二区三区| 亚洲免费视频在线观看| 亚洲精品免费在线观看| 在线免费观看国产| 免费国产成人高清在线观看网站| 日本免费xxxx色视频| 欧美a级在线现免费观看| 女人18毛片特级一级免费视频| 天天操夜夜操免费视频|