Web|window| Program | page | implementation
Many companies now face a challenge: How to execute Windows applications that exist in a web environment. Here is a description of the technology to implement this function, it strives for the generation
Code to make the smallest changes in the Windows environment to complete everything that should be done.
Existing Windows applications
The Windows example program that you want to execute on the web is very simple, it's written in VB, and it has a form. At run time, show the employee's letter on the form
, this information comes from a table in an Access database. The form has a single, Next, Previous, and last buttons that allow users to browse records. While
You can also change the data by button Add, Delete, and update.
This program communicates with the database through a COM class, and it has the following methods:
AddEmployee () Add a record to the table and save the information for the new employee
UpdateEmployee () Update a record
Deleteemployee () Deletes a record
GetEmployees () Get information for an employee
When the program is running correctly, the browser displays the following:
Developing Web Applications
In traditional Web applications, most of the processing is done on the server side. Here, we will try to do some processing on the client to reduce the work on the server
Volume. That is, let the client complete the processing of the display information and leave the business rules and database access to the server side. This is like an n-tier processing model.
When the user needs to access another different data, we do not want to transfer from the server to the entire Web page, therefore, we need to find a Web client in the background and
How the Web server communicates information. In this example, we use Microsoft's XMLHTTP COM object component, which comes with Internet Explorer 5.0
Of Of course, you can also write a Java applet that functions like this to overcome this limitation.
Server-side code
Let's start with a study of the COM classes of VB applications to the Web, which can be done by writing ASP pages to invoke each method in the COM class
(Addemployee.asp, updateemployee.asp, deleteemployee.asp, getemployee.asp). Knowing these, you can access COM in the Web
Class method.
ASP pages should be able to accept the same parameters as COM classes that send calls to the original COM class. The main difference here is that all output is in XML format
Of We use another COM class called Xmlconverter, and the output of the conversion method is in XML format. Xmlconverter's code is included in the download file, which has a
function to accept an ADO recordset as a parameter and convert it to an XML document. The function examples for this purpose can be easily found from the Internet, more than
Such as:
Http://www.vbxml.com/xml/guides/developers/ado_persist_xml.asp
We may have used the Save function of the ADO recordset, plus adPersistXML, to save it in XML format, but here, for simplicity, I
are still using the compiled function.
The following code comes from Getemployees.asp, which executes the GetEmployees method so that you can see this technique clearly:
<script Language=vbscript runat=server>
' Declare the above described Xmlconverter
Dim Objxmlconverter
' Create the Xmlconverter object on the Web server machine
Set Objxmlconverter = Server.CreateObject ("Xmlconverter.clsxmlconverter")
' Declare the above described Employeemgr object
Dim Objemployeemgr
' Create the Employeemgr object on the Web server machine
Set objemployeemgr = Server.CreateObject ("Employeemgr.clsemployeemgr")
' Declare a String varaible
Dim strxml
Now call the employees () method of the Employees object, which returns an ADO Recordset object that we pass to the Xmlconverter object's
Xmlrecordset () method, Xmlrecordset () is responsible for converting an ADO recordset into an XML document. Finally, we retrieve the XML document and deposit it in the strxml character
In a string variable:
Strxml = Objxmlconverter.xmlrecordset (objemployeemgr.getemployees)
' Destroy the Employeemgr object
Set objemployeemgr = Nothing
' Destroy the Xmlconverter object
Set Objxmlconverter = Nothing
' Write the XML Document as the ' response
Response.Write Strxml
</SCRIPT>
Then, create the page addemplyee.asp, deleteemployee.asp, and updateemployee.asp in the same way.
Client's Code
Now ready to write the client code, first, let's take a closer look at how the VB application displays the information after the call. In the VB form of the On_load method (see the following
Code), we call the COM object component GetEmployees method, which returns an ADO recordset with employee information. MoveFirst of ADO recordset
(), MoveNext (), and the MoveLast () method establish a method for recording browsing.
Private Sub Form_Load ()
' Create the Employeemgr Object '
Set objemplyeemgr = New clsemployeemgr
' Obtain the Employee Records in a ADODB. Recordset
Set rst = Objemplyeemgr.getemployees
Rst. MoveFirst
Displaycurrentrecord
End Sub
In this case, we have an ASP page getemployees.asp, which gives the information as an XML document. So we're going to build a Web client
Xmldom the object, and the information provided by Getemployees.asp is transferred. In this example, we use Microsoft DOM XML to parse. About DOM XML Solutions
For a complete documentation of the analysis, refer to the MSDN articles, such as XML DOM Objects.
Another good solution is to use pure java/javascript, which can also be applied on non-Internet Explorer browsers. Here, we still use
XMLHTTP object that enables a Web client to establish an HTTP request to a Web server. For a detailed description of XML HTTP, refer to the documentation on MSDN.
Create a xmldom on the Web Client machine
var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
node pointing at Root node of the XML Document
var noderoot;
node to point at the current record
var Nodecurrentrecord;
Integer pointing at the current record number
var ncurrentindex = 0;
Create the Microsoft XMLHTTP object on the Web client machine
This would have to being present and registered on the client machine
Installing Internet Explorer 5.0 satisfies this requirement
var objhttprequest = new ActiveXObject ("Microsoft.XMLHTTP");
Open a HTTP connection to the URL in strURL
Objhttprequest.open ("Get", strURL, FALSE, NULL, NULL);
Send the request
Objhttprequest.send ();
Obtain the response received to the Xmlresponse variable
This response would is the XML document returned by the Web server
var xmlresponse = Objhttprequest.responsetext
Since The response is a XML document we can load it to a XmlDoc object
Xmldoc.loadxml (Xmlresponse);
Set Noderoot to point at the root of the XML document
Noderoot = xmldoc.documentelement;
From the above we understand the structure of the XML document, you can now carefully study the XML Document object. We'll write a client-side JavaScript function
Rstmovefirst (), which can move the current record pointer to 1th, similar to the MoveFirst method of an ADO recordset:
function Rstmovefirst () {
Error trap for empty record set
if (NodeRoot.childNodes.length < 1) {
If The root node does not have any child nodes then there are
No "records"
return false;
}
Ncurrentindex = 0;
Set the "Nodecurrentrecord to" at the 0th child of the
XML Document. The 0th child would is the "the".
Noderoot is the XML document? DocumentElement
Nodecurrentrecord = Noderoot.childnodes (Ncurrentindex);
Return Success
return true;
}
Again, we can write the Rstmovenext () and Rstmovelast () functions, and by writing this code we will be able to understand the XML document elements carefully. And
Then write a function similar to the ADO recordset Upadte method.
Now we have created a fake ADO Recordset object on the client, so we can work with these "recordsets" as we do in a VB application.
With these functions, the rest is to write the user interface, as in a VB application. For example, in a VB application, "Move to 1th record" after
The code is:
Private Sub Btnfirst_click ()
If not (rst. EOF and RST. BOF) Then
' Move to the '
Rst. MoveFirst
' Displaycurrentrecord is a function ' This display the current ' records information
Displaycurrentrecord
End If
End Sub
In the Web application, the corresponding code is:
function Btnfirstclick () {
' Move to the ' recordset
' This is our Rstmovefirst returns True if
' It was successful and false if EOF and BOF
if (Rstmovefirst ()) {
' Here's Displaycurrentrecord is client side JavaScript
' function that display the current records information on
' The screen
Displaycurrentrecord ();
}
}
When the actual database needs to be updated, the update message is sent to updateemployee.asp, which will be more updateemployee through the COM object's method
The new database. The application described above, exported to the Web, will display the following figure:
Conclusion
In Web applications, you want to set up an appropriate schedule to transform an ADO recordset into an XML document. Once the definition is clear, applications like that standard will be implemented well. The other one I
The domain that we want to study is the manipulation function of the client recordset (that is, the rst* function). We can write Java applets to handle these recordset manipulation functions so that the guest
A Java Recordset object is established on the user side. This approach will be a very object-oriented approach.
Click here to download the relevant information of this article:
Http://www.asptoday.com/articles/images/20000602.zip