当前位置:编程学习 > JAVA >>

B/S离线技术设计与实现

其实B/S的离线很好办,数据在缓存中就可以实现,但如果有数据回调或是数据验证,就不问题了.
所以实现我个人认为有这相几个方法:
方法一:
    1)数据缓以数组或XML缓存在客户端的网页中,用JS进行交互;
    2)保存时,如果联机就直接保存到服务器,如果断线就保存在网页的XML或JS数组;
    3)网络接通时,用XMLHTTP方式将离线数据上传到服务器
方法二:
     1)数据缓存到客户端的XML文件,也JS的方式加载到页面;
     2)保存时,文件先保存在客户端XML文件,如果网络联机就直接送到服务器,并清空XML;
     3)网络接通进,将XML同步到服务器
两种方式都可以实现离线和断电功能;也各有优点,
      方法一就是用户不能关闭当前的网站或系统,因为XML可用是以Frame的方隐藏的网页上的,关闭后,数据一样丢失..
      方法二需要解决在客户端读写文件的权限与加解密问题;
我个人选择的是方法二,用ActievX + 数字签名 + XML + MD5文件验证实现

Javascript代码 
<script type="text/javascript" > 
function SearchData() 

var InputParam; 
InputParam = document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit1").UniqueID %>').value; 
 
for(var i=0;i<cst10100[0].length;i++) 
    { 
    if(cst10100[0][i]==InputParam) 
        { 
        igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit2").UniqueID %>').setValue(cst10100[4][i]); 
        igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit3").UniqueID %>').setValue(cst10100[7][i]); 
        igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit4").UniqueID %>').setValue(cst10100[5][i]); 
        igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit5").UniqueID %>').setValue(cst10100[6][i]); 
        igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit8").UniqueID %>').setValue(cst10100[2][i]); 
        } 
    } 
var ListBoxControl=document.getElementById('<%= this.UltraWebTab1.FindControl("ListBox1").UniqueID %>'); 
for(var z=ListBoxControl.options.length;z>0;z--) 

    ListBoxControl.options[z-1].parentNode.removeChild(ListBoxControl.options[z-1]); 

for(var z=0;z<cst10101[0].length;z++) 

    if (cst10101[0][z]==InputParam) 
    {            
             var   newOption=document.createElement("OPTION");            
             newOption.text=cst10101[3][z];   
             newOption.value=cst10101[3][z];    
             ListBoxControl.options.add(newOption);  
      }       
}  
 
var dropdownlistControl=document.getElementById('<%= this.UltraWebTab1.FindControl("DropDownList2").UniqueID %>'); 
for(var z=dropdownlistControl.options.length;z>0;z--) 

    dropdownlistControl.options[z-1].parentNode.removeChild(dropdownlistControl.options[z-1]); 

for(var z=0;z<cst10101[0].length;z++) 

    if (cst10101[0][z]==InputParam) 
    {            
             var   newOption=document.createElement("OPTION");            
             newOption.text=cst10101[1][z];   
             newOption.value=cst10101[1][z];    
             dropdownlistControl.options.add(newOption);  
      }       
}   
   

 
//设置时间 
var igdrp =igdrp_getComboById('<%= this.UltraWebTab1.FindControl("WebDateChooser1").UniqueID %>'); 
igdrp.setText('2007-4-11'); 
 
//添加节点 
for(var z=0;z<cst10104[0].length;z++) 

             var resultId=document.getElementById('<%= this.UltraWebTab1.FindControl("DropDownList1").UniqueID %>'); 
             var   newOption=document.createElement("OPTION");   
             newOption.text=cst10104[1][z];   
             newOption.value=cst10104[0][z];   
             resultId.options.add(newOption);   

</script> 
 
<IE:CLIENTCAPS   ID="oClientCaps"   style=behavior:url(#default#clientCaps)/>   
<script type="text/javascript" > 
 
function getstatus() 

    if(oClientCaps.connectionType=="lan") 
        return "online"; 
    else 
        return "offline"; 

 
function runClock() 

    theTime = window.setTimeout("runClock()", 1000); 
    status=getstatus(); 
    //if (getstatus() =="online") 
        //判断本地是否有离线数据,当存在时进行同步 
        //SyncXML() 

runClock() 
 
function InsertData() 

    var CommonArry= new Array(); 
    CommonArry[0]= new Array(); 
    CommonArry[0][0]= 'cust';   
    CommonArry[0][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit1").UniqueID %>').value; // value 
    CommonArry[0][2]= "2";  &nb

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,