有三个文件: Rs.asp :在服务器端进行引用,来完成服务器端的初始化工作 Rs.Htm :其实它是一个JavaScript 脚本文件,使用完成请求分析数据 Rsproxy.class :是一个Java 小程序,就是通过它来完成客户端与服务端的通信 -------- 服务端文件 Server.asp---- <%@ LANGUAGE=VBSCRIPT %> <!--#include file="_ScriptLibrary/rs.asp"--> //必须要包含这个文件 <% RSDispatch %> //对 Remote Scripting 进行初始化,必须第一个调用 <SCRIPT Language=JavaScript RUNAT=SERVER> function Description(){ this.myFunction = myFunction; //暴露myFunction函数 } public_description = new Description(); function myFunction(strInput, numLength) //在这里实现这个myFunction 函数 { var objConn = Server.CreateObject("ADODB.Connection"); objConn.Open("dsn=pubs;uid=sa;pwd=;Network=DBMSSOCN"); var objRS = Server.CreateObject("ADODB.Recordset"); objRS.MaxRecords = numLength; objRS.Open("SELECT au_lname, au_fname FROM Authors Where (au_lname + ', ' + au_fname) >= '" + strInput + "' ORDER BY au_lname,au_fname", objConn, 0, 3); var tmpMsg = new String; tmpMsg.value = ""; while (!objRS.EOF){ tmpMsg.value = tmpMsg.value + objRS("au_lname") + ", " + objRS("au_fname") + ":"; objRS.MoveNext(); } objConn.Close(); return tmpMsg.value; } </SCRIPT>
--------------客户端 RSClient.HTM ------ <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <TITLE>Servin' It Up with Remote Scripting</TITLE> <BODY onload="refresh_list()"> //当页面载入时调用函数 refresh_list() <SCRIPT Language="JavaScript" src="_ScriptLibrary/rs.htm"> //这是客户端必须的引入 </SCRIPT> <H2>Address Book Sample</H2> <FORM id=form1 name=form1> <INPUT type="text" size="50" id=Myname name=MyName onkeyup=refresh_list()><br> <SELECT id=NameList name=NameList size=10> - One Moment Please -----</SELECT> </FORM> <SCRIPT LANGUAGE=javascript> <!-- RSEnableRemoteScripting(); //初始化客户端脚本,建立连接对象 function refresh_list(){ var serverURL = "server.asp"; //服务器端文件 var DisplayLength = 10 document.form1.NameList.length = 0 document.form1.NameList.length = DisplayLength var inValue = document.form1.MyName.value; var myVar = RSExecute(serverURL, "myFunction", inValue, DisplayLength);//进行远程调用 var myArray = myVar.return_value.split(":"); //返回值只能是String类型 for (i = 0; i < 10; i++){ //下面对得到的数据进行分析 var myOpt = new Option myOpt.value = myArray[i]; myOpt.text = myArray[i]; if (i < myArray.length){ document.form1.NameList.options[i] = myOpt; } } document.form1.NameList.options[0].selected = true; } //--> </SCRIPT> </BODY> </HTML> |