ASP provides unlimited scalability through ActiveX Server Components (ActiveX Server component. In ASP development, components are inevitably used. There are indeed many free and trial components on the Internet. However, this is something that people may not worry about when using, components written by yourself can be used practically. ActiveX Server component can be written in Visual Basic, Delphi, Java, Visual C ++, COBOL, and other programming languages. This document describes how to use Java to write ASP components.
First, 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 and generate testjava. Class and register it as a component.
Register Java components: This program can be found in Microsoft SDK for Java. Install Microsoft SDK for Java first. The latest version is 4.0. : The mricrosoft SDK for Java 4.0 If the error occurs, go to the http://www.microsoft.com. Download and install it directly. This tool is available in the bin directory of Microsoft SDK for Java after installation. Before registering, you can copy the compiled class file to the/Java/trustlib/directory under the system directory (C:/winnt/Java/trustlib on my machine ). In the "command prompt" window, enter javareg and execute it. You may see its usage and parameters. For example:
| Javareg/register/class: testjava/progid: component. testjava |
Register the class file generated above You can use a Chinese name. Just register javareg/unregister. Note: If you re-compile your Java program and want it to take effect immediately, you must restart the Web server so that it can be used normally. Otherwise, you will find that the newly added method cannot be used. Use in ASP:
<% 'Testjava. asp Set OBJ = server. Createobject ("component. testjava ") Response. Write obj. lenstr ("Hello! Hello world! ") Response. Write "<br>" & obj. Version Response. Write "<br>" & obj. Ver OBJ. asptest Set OBJ = nothing %> |
Save as testjava. asp Make sure your web server is working, and check the result in the browser! About Using ASP built-in objects: If response. Write ("Hello world! "), It will be very convenient. The following describes how to use ASP built-in objects. Open the Java subdirectory in the Windows System directory. If IIS or PWS is installed, a directory named trustlib is displayed. Open Com/MS/asp, there is something that can be used in Java ActiveX components, use these built-in objects, as long as they "import" in, you can Obtain the ASP built-in object 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) CTX. getobjectcontext (); Vari = ICP. getproperty ("response "); Iresp = (iresponse) vari. getdispatch (); Iresp. Write (new variant ("} } |
Use ASP to test:
<% 'Testjava. asp Set OBJ = server. Createobject ("component. testjava ") Response. Write obj. lenstr ("Hello! Hello world! ") Response. Write "<br>" & obj. Version Response. Write "<br>" & obj. Ver OBJ. asptest Set OBJ = nothing %> |
The result is as follows: 15 1.0.1 1.0.1 Java ActiveX Components Note: This Java program must use Microsoft SDK for Java compilers to successfully compile (use jvc.exe). In addition, there are detailed examples of ASP under the samples/asp installation directory of Microsoft SDK for Java. |