Writing ASP Components in Java

Source: Internet
Author: User
Tags return
Using Java to write ASP components Source: http://www.edulife.com.cn/Infos/189912/30189912006858.html


ASP makes it infinitely extensible through an ActiveX server components (a component of ActiveX servers). In the development of ASP, avoid the use of components, the Internet does have a lot of free, trial components, but this is someone else's things, use up some worry, the component of their own to use up the 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.

First, write a very simple Java program

public class Testjava
{
Public String ver= "1.0.1 version";

public int lenstr (String str)
{
return Str.length ();
}

Public String Version ()
{
return Ver;
}
}

Compile the build testjava.class and register it as a component.

To register a Java component:
Perhaps most people think of RegSvr32.exe this program, but this is not used, it is used to register the ActiveX components compiled into DLLs, Java written class file can not be used to register, you need is JavaReg.exe, this program in Microsoft Can be found in SDK for Java. You first install the Microsoft SDK for Java, and the latest version is the 4.0 version. Download Address:
Mricrosoft SDK for Java 4.0
If you're wrong, go to the http://www.microsoft.com and find it. Install it directly after downloading.
This tool is available in the Microsoft SDK for Java Bin directory after installation. Before registering, you can copy the compiled class file to the \java\trustlib\ directory under the system directory (on My computer is C:\winnt\java\trustlib). Enter JavaReg and execute it under the Command Prompt window, and you may see its usage and parameters.
Such as:

Javareg/register/class:testjava/progid: Components. Testjava

Register the class file generated above
You can use the Chinese name. Reverse Registration Javareg/unregister ... On the line. Note: If your Java has been recompiled and wants to take effect immediately, you will need to restart the Web server to work properly, or you may find that the new method is not available.

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 then look at the results in the browser!

about using ASP built-in objects:
If you can use Response.Write ("Hello world! "), then it will be very convenient. Here's a quick overview of how to use ASP built-in objects.
You open the Java subdirectory under the Windows system directory, and if you install IIS or PWS, you will have a more directory Trustlib
With the com\ms\asp open, there is something in the Java ActiveX component that you can use, using these built-in objects, and just import them in to
In the Java ActiveX component, obtain an ASP-built object, as follows:

public class Testjava
{
Public String ver= "1.0.1 version";

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 (New Variant ("}
}


Test with 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
%>


The results are as follows:

15
1.0.1 Edition
1.0.1 Edition
Java ActiveX Components

Note: This Java program will use the Microsoft SDK for Java compiler to compile successfully (using Jvc.exe), and a detailed example of the ASP is available under the Microsoft SDK for Java installation directory samples\asp.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.