⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在web页面中执行windows程序.htm

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.abc800.com/news/artdetail.asp?id=313 -->
<HTML><HEAD><TITLE>在Web页面中执行Windows程序</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR><LINK 
href="在Web页面中执行Windows程序.files/putong_1t" rel=StyleSheet type=text/css>
<SCRIPT language=javascript 
src="在Web页面中执行Windows程序.files/fun_Script.js"></SCRIPT>
</HEAD>
<BODY background=在Web页面中执行Windows程序.files/r_bg.gif>
<P align=center><BR></P>
<TABLE align=center class=tableFrame height=311 width="90%">
  <TBODY>
  <TR align=middle>
    <TD align=right bgColor=#decbad class=listcelltitle height=274 vAlign=top 
    width=717>
      <P align=center><BR><FONT color=#000000 
      style="FONT-SIZE: 14px"></FONT><FONT color=#000080 
      style="FONT-SIZE: 14px"><B>在Web页面中执行Windows程序</B></FONT><FONT 
      color=#000000 style="FONT-SIZE: 14px"><BR></P>
      <P align=right>更新日期:2002-9-26 阅读次数:186</FONT></P>
      <P align=left 
      style="FONT-SIZE: 14px">现在许多公司都面临一个难题:如何在Web环境中执行存在的Windows应用程序。这里就介绍实现这个功能的技术,它争取对代<BR>码做最小的改变,完成在Windows环境中应做的一切。<BR><BR>现存的Windows应用程序<BR><BR>  这里想要在Web中执行的Windows例子程序是非常简单的,它是用VB编写的,其中有一个表单。运行时,在表单上显示雇员的信<BR>息,这些信息来源于Access数据库的一个表。表单上设有First、Next、Previous 
      和 Last按钮,从而允许用户浏览记录。同时,<BR>还可以通过按钮Add、Delete 和 
      Update来改变数据。<BR><BR>这个程序通过一个COM类来与数据库通信,它有下面的方法:<BR><BR>AddEmployee() 
      在表中添加一个记录,保存新雇员的信息 <BR>UpdateEmployee() 更新一个记录 <BR>DeleteEmployee() 删除一个记录 
      <BR>GetEmployees() 获取一个雇员的信息 
      <BR><BR>程序正常运行时,浏览器显示如下:<BR><BR><BR>开发Web应用程序<BR><BR>  在传统的web应用程序中,大多数的处理都是在服务器端完成的。这里,我们将尝试在客户端做一些处理,以减少服务器上的工<BR>作量。也就是,让客户端完成显示信息的处理工作,并将商业规则和数据库存取留给服务器端。这就象一个n层处理模型。<BR><BR>  当用户需要访问另一个不同的数据时,我们也不想从服务器上再调入整个web页面,因此,需要找到一个web客户端在后台与<BR>web服务器交流信息的方法。这个例子中,我们使用了微软公司的XMLHTTP 
      COM对象组件,它是随Internet Explorer 5.0而来<BR>的。当然,也可以编写一个功能类似的Java 
      applet来克服这个局限。<BR><BR>服务器端的代码<BR><BR>  让我们从研究VB应用程序的COM类到Web的每一个方法开始,这可以通过编写ASP页面来调用COM类中的每个方法实现<BR>(AddEmployee.asp, 
      UpdateEmployee.asp, DeleteEmployee.asp, GetEmployee.asp)。 
      明白了这些,就能够在Web中存取COM<BR>类方法了。<BR><BR>  ASP页面应该能够接受与COM类一样的参数,这些页面向原始的COM类发送调用。这里主要的区别就是所有的输出是以XML格式<BR>的。我们使用另外一个叫XMLConverter的COM类,转换方法的输出为XML格式。XMLConverter的代码包含在下载文件中,它有一个<BR>函数,能够接受一个ADO记录集做为参数,并且转换为一个XML文档。实现这个目的的函数例子可以从Internet上很容易地找到,比<BR>如:<BR><BR>http://www.vbxml.com/xml/guides/developers/ado_persist_xml.asp<BR><BR>  我们也许曾经使用过ADO记录集的Save函数,加上adPersistXML,来实现按照xml格式保存,但是在这里,为了简单起见,我<BR>们仍使用编制的函数。<BR><BR>下面的代码来自GetEmployees.asp,它执行GetEmployees方法,从而可以让你清晰地看到这种技术:<BR><BR>&lt;SCRIPT 
      LANGUAGE=vbscript RUNAT=Server&gt;<BR>'Declare the above described 
      XMLConverter<BR>Dim objXMLConverter<BR><BR>'Create the XMLConverter object 
      on the web server machine<BR>Set objXMLConverter = 
      Server.CreateObject("XMLConverter.clsXMLConverter")<BR><BR>'Declare the 
      above described EmployeeMgr object<BR>Dim objEmployeeMgr<BR><BR>'Create 
      the EmployeeMgr object on the web server machine<BR>Set objEmployeeMgr = 
      Server.CreateObject("EmployeeMgr.clsEmployeeMgr")<BR><BR>'Declare a String 
      varaible<BR>Dim 
      strXML<BR><BR><BR>  现在调用Employees对象的Employees()方法,它将返回一个ADO记录集对象,我们将这个对象传递给XMLConverter对象的<BR>xmlRecordset()方法,xmlRecordset()负责将ADO记录集转换为XML文档。最后,我们取回XML文档,并将它存入strXML字符<BR>串变量中:<BR><BR>strXML 
      = 
      objXMLConverter.xmlRecordset(objEmployeeMgr.GetEmployees)<BR><BR>'Destroy 
      the EmployeeMgr object<BR>Set objEmployeeMgr = Nothing<BR><BR>'Destroy the 
      XMLConverter object<BR>Set objXMLConverter = Nothing<BR><BR>'Write the XML 
      Document as the response<BR>Response.Write 
      strXML<BR>&lt;/SCRIPT&gt;<BR><BR><BR>然后,用同样的方式来创建页面AddEmplyee.asp、DeleteEmployee.asp和UpdateEmployee.asp。<BR><BR>客户端的代码<BR><BR>  现在准备编写客户端代码,首先,让我们仔细看看VB应用程序在调用后如何显示信息。在VB表单的On_Load方法(参见下面的<BR>代码)中,我们调用了COM对象组件GetEmployees方法,这个方法返回一个附带雇员信息的ADO记录集。ADO记录集的MoveFirst<BR>()、MoveNext()以及 
      MoveLast() 方法建立了记录浏览的方法。<BR><BR>Private Sub Form_Load()<BR>'Create the 
      EmployeeMgr Object<BR>Set objEmplyeeMgr = New 
      clsEmployeeMgr<BR><BR>'Obtain the Employee Records in a 
      ADODB.Recordset<BR>Set rst = 
      objEmplyeeMgr.GetEmployees<BR>rst.MoveFirst<BR>DisplayCurrentRecord<BR>End 
      Sub<BR><BR><BR>  在这种情况下,我们有一个ASP页面GetEmployees.asp,它给出了做为XML文档的信息。所以我们将在web客户端建立一个<BR>XMLDOM对象,并且调入由GetEmployees.asp提供的信息。在这个例子中,我们使用Microsoft 
      DOM XML来解析。关于DOM XML解<BR>析的完整文档,请参考MSDN有关文章,比如 XML DOM 
      Objects。<BR><BR>  另一个较好的解决方法是使用纯Java/JavaScript,它同时可以在非Internet 
      Explorer的浏览器上应用。这里,我们仍使用<BR>XMLHTTP对象,它可以让web客户端建立一个到web服务器的HTTP请求。关于对XML 
      HTTP的详细描述,请参考MSDN上的文档。 <BR><BR>//Create an XMLDOM on the Web Client 
      machine<BR>var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");<BR><BR>// 
      node pointing at Root node of the XML Document<BR>var nodeRoot;<BR><BR>// 
      node to point at Current Record<BR>var nodeCurrentRecord;<BR><BR>// 
      Integer pointing at the current Record number<BR>var nCurrentIndex = 
      0;<BR><BR><BR>//Create the Microsoft XMLHTTP object on the web client 
      machine<BR>//This would have to be present and registered on the client 
      machine<BR>//Installing Internet Explorer 5.0 satisfies this 
      requirement<BR>var objHTTPRequest = new 
      ActiveXObject("Microsoft.XMLHTTP");<BR><BR>//Open a http connection to the 
      URL in strURL<BR>objHTTPRequest.Open ("GET", strURL, false, null, 
      null);<BR><BR>//Send the request<BR>objHTTPRequest.send();<BR><BR>//Obtain 
      the response received to the xmlResponse variable<BR>//This response would 
      be the XML document returned by the web server<BR>var xmlResponse = 
      objHTTPRequest.responseText<BR><BR>//Since the response is an XML document 
      we can load it to an xmlDoc object<BR>xmlDoc.loadXML 
      (xmlResponse);<BR><BR>//Set nodeRoot to point at the root of the xml 
      document<BR>nodeRoot = 
      xmlDoc.documentElement;<BR><BR><BR>  从上面我们了解了XML文档的结构,现在可以仔细研究XML文档对象了。我们将编写一个客户端的JavaScript函数 
      <BR>rstMoveFirst(),它可以移动当前记录指针到第1条,这与ADO记录集的MoveFirst方法类似:<BR><BR>function 
      rstMoveFirst() {<BR>//Error trap for empty record set<BR>if 
      (nodeRoot.childNodes.length; &lt; 1) {<BR><BR>//If the root node does not 
      have any child nodes then there are<BR>//no "records"<BR>return 
      false;<BR>} <BR>nCurrentIndex = 0;<BR><BR>//Set the nodeCurrentRecord to 
      point at the 0th child of the <BR>//XML Document. The 0th child would be 
      the first record.<BR>// nodeRoot is the XML document? 
      documentElement<BR>nodeCurrentRecord = 
      nodeRoot.childNodes(nCurrentIndex);<BR><BR>//Return Success<BR>return 
      true;<BR>} <BR><BR><BR>  同样,我们可以编写rstMoveNext()和 
      rstMoveLast()函数,通过编写这些代码,我们将能仔细地了解XML文档元素。而且,<BR>再编写一个类似于ADO记录集upadte方法的函数。<BR><BR>  现在我们在客户机上创建了一个假冒的ADO记录集对象,因此就可以象在VB应用程序中一样来处理这些“记录集”。<BR><BR>  有了这些函数,剩下的就是编写用户界面,这就象在VB应用程序中一样。比如,在VB应用程序中,“移动到第1条记录”后面<BR>的代码是:<BR><BR>Private 
      Sub btnFirst_Click()<BR>If Not (rst.EOF And rst.BOF) Then<BR><BR>'Move to 
      the first record<BR>rst.MoveFirst<BR><BR>'DisplayCurrentRecord is a 
      function that display the current 'records information 
      <BR>DisplayCurrentRecord<BR><BR>End If<BR>End 
      Sub<BR><BR><BR>在web应用程序中,相应的代码是:<BR><BR>function btnFirstClick() 
      {<BR>'Move to the first record in the recordset<BR>'Note that our 
      rstMoveFirst returns True if<BR>'it was successful and false if EOF and 
      BOF <BR>if (rstMoveFirst()) {<BR>'Here DisplayCurrentRecord is client side 
      JavaScript<BR>'function that display the current records information 
      on<BR>'the the 
      screen<BR>DisplayCurrentRecord();<BR>}<BR>}<BR><BR>  当需要更新实际的数据库时,就发送更新信息给UpdateEmployee.asp,这个页面将通过COM对象的UpdateEmployee方法来更<BR>新数据库。上面描述的应用程序,输出到web上,将显示如下图:<BR><BR><BR>结论<BR><BR>  在web应用中,要建立适当的计划来转换ADO记录集为XML文档。一旦定义明确了,象那样标准的应用将很好实现。另外一个我<BR>们想研究的领域是客户端记录集的操纵函数(就是rst*函数)。我们可以编写Java 
      applet来处理这些记录集操纵函数,从而在客<BR>户端建立了Java记录集对象。这种方法将是很面向对象的一种处理方法。<BR><BR>点击此处下载本文相关资料:<BR>http://www.asptoday.com/articles/images/20000602.zip 
      <BR><BR><BR><BR><BR>原作者:luoxh(转)<BR>来 源:chinaasp <BR></P></TD></TR>
  <TR>
    <TD align=right bgColor=#decbad class=listcelltitle height=29 vAlign=top 
    width=717><INPUT class=button name=Submit2 onclick=javascript:window.close() style="FONT-SIZE: 9pt" type=button value=关闭窗口> 
      &nbsp; </TD></TR></TBODY></TABLE><BR></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -