Write an ASP component with Java

zhaozj2021-02-08  260

Write an ASP component with Java

(Programming Xu Changyou)

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 to generate TestJava.class and register it 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:

Javareg / Register / Class: Testjava / Progid: Components. Testjava

Registering the Class files generated above can be used in 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.aspset obj = server.createObject ("Component .testjava") response.write obj.Lenstr ("Hello! Hello World!") response.write "
" & obj.versionResponse.write "< Br> "& obj.verobj.asptestset Obj = NOTHING%>

Saved as testjava.asp to determine your web server at work, then look at the results 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 Components ));}}

Test with ASP:

<% 'testjava.aspset obj = server.createObject ("Component .testjava") response.write obj.Lenstr ("Hello! Hello World!") response.write "
" & obj.versionResponse.write "< Br> "& obj.verobj.asptestset Obj = NOTHING%>

The results are as follows:

151.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), and there is a detailed example of the ASP under the Samples / ASP of the Microsoft SDK for Java installation directory.

I hope this article can help you!

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

New Post(0)