Creating Visual J++ COM Components for ASP

IIS 6.0

When you develop your component with Microsoft Visual J++?, you create classes that expose methods. When an ASP script calls your component, the Microsoft Virtual Machine (VM) exposes your class file as a COM component.

Your Java component can access the ASP built-in objects by calling the Java class files that are created when you install IIS. These classes use native Java types and support native Java interfaces. You can refer to these classes directly, but the Microsoft Windows Foundation Classes (WFC) greatly simplify creating components to run on IIS. The WFC creates new interfaces that expose the ASP object model. The goal is to retain all of the features of the ASP programming model and to expose it in a way that is more natural for the Java programmer.

WFC includes a class called AspContext. The AspContext class greatly simplifies accessing the ASP built-in objects for Java programmers. The following code demonstrates using AspContext to obtain a reference to the Response object.

package GetResponse; 

public class wfcgetResponse 
   public boolean myResponse() 
      Response myResponse = AspContext.getResponse(); 
      myResponse.write("Hello there"); 
      return true; 

If you develop components with Visual J++ 1.1, then you need to register the class that implements your component with the javareg.exe tool, which is installed with the VM. If you implement your component as a java class file, you need to register your component. Visual J++ 6.0 provides a new tool, vjreg.exe, to register java class files.

Visual J++ 6.0 eliminates the need to register the class with javareg.exe because you can implement the class as a dynamic link library (DLL). When you implement the class as a DLL, the class is automatically registered when you build the component.

One unique aspect of implementing a Java component is that you can create an instance of a Java classin an ASP file by using a Java Moniker. A Java Moniker is a string that describes the name of the class you want to create an instance of, including a package name, if any. You use the Java Moniker to create an instance of an object from your component in exactly the same way a ProgID is used with Server.CreateObject.

The following code example uses the JScript programming language in an ASP page to create an instance of the wfcgetResponse class from the GetResponse Java component whose example code is listed above.

<% @LANGUAGE="JScript" %> 
  var myObject; 
  myObject = getObject("java:GetResponse.wfcgetResponse"); 
MyResponse is <%= myObject.myResponse %> 


Objects created by calling GetObject instead of Server.CreateObject cannot access the ASP built-in objects through the COM+ ObjectContext object and therefore cannot participate in a transaction.