Write an ASP component with Java

xiaoxiao2021-03-05  21

Write an ASP component with Java Source: http://www.edulife.com.cn/infos/189912/30189912006858.html

The ASP has an infinitely expandability through the ActiveX Server Components. Among the ASP development, there is no use of components, there is indeed a lot of free, trial components, but this is something that people use, it is always worried, and the components written by themselves are practical. ActiveX Server Component can be written using Visual Basic, Delphi, Java, Visual C , COBOL and other programming languages. This article mainly describes how to use Java to write ASP components. Write a very simple Java program

Public class testjava {public string ver = "1.0.1"; public int LENSTR (String Str) {Return str.Length ();} public string version () {return ver;}} Compile generation testjava.class, then It registers into components. Register Java Components: Maybe most people think of this program, but not here, it is used to register the ActiveX component written to DLL, and the Class file written by Java cannot be registered with it. You need Javareg .exe, this program can be found in Microsoft SDK for Java. You first install Microsoft SDK for Java, and the latest version is version 4.0. Download address: MRICROSOFT SDK for Java 4.0 If it is incorrect, go to http://www.microsoft.com. Install directly after downloading. After installation, there is this tool in the BIN directory of Microsoft SDK for Java. Before you register, you can copy compiled Class files to / java / trustlib / directory in the system directory (in my machine is C: / Winnt / Java / TrustLib). Enter Javareg under the "Command Prompt" window and execute, it may see its usage and parameters. Such as:

Javaareg / Register / Class: Testjava / Progid: Component. Testjava Register the Class file generated above to use the Chinese name. Reverse registration javareg / unregister ... Note: If your Java recompiled, I want to take effect immediately, I must restart the web server, so that you can use it normally, otherwise you will find new methods that cannot be used. Use in ASP:

<% `Testjava.asp set obj = server.createObject (" Components .testjava ") response.write obj.Lenstr (" Hello! Hello World! ") Response.write"
"& obj.version response.write "
" & obj.ver obj.asptest set obj = not%> Saved as testjava.asp to determine your web server at work, then look at the result in the browser! About using an ASP built-in object: If you can use Response.Write ("Hello World!"), It will be convenient. Let's take a brief introduction how to use the ASP built-in object. You open the Java subdirectory in the Windows system directory. If you install IIS or PWS, you will be able to open COM / MS / ASP after installing IIS or PWS, which is available in the Java ActiveX component, using these built-in objects. As long as they "import" comes in, the ASP built-in object can be obtained in the Java ActiveX component, the program is as follows: Public class testjava {public string ver = "1.0.1"; public int LENSTR (String str) {Return Str .length ();} public String Version () {return Ver;} public void asptest () {IGetContextProperties icp; Variant vari = new Variant (); IResponse iresp; icp = (IGetContextProperties) MTx.GetObjectContext (); vari = icp .GetProperty ("response"); IRESP = (IRESPONSE) vari.getdispatch (); IRESP.WRITE ("

Java ActiveX Component ));}} Test with ASP:

<% `Testjava.asp set obj = server.createObject (" Components .testjava ") response.write obj.Lenstr (" Hello! Hello World! ") Response.write"
"& obj.version response.write "
" & obj.ver obj.asptest set obj = Nothing%> The results are as follows: 15 1.0.1 version 1.0.1 Java ActiveX Component Note: This Java program uses the Microsoft SDK for Java compiler to successfully compile ( Using JVC.exe), there is a detailed example of the ASP under the Samples / ASP of the Microsoft SDK for Java installation directory.

转载请注明原文地址:https://www.9cbs.com/read-32377.html

New Post(0)