If you choose to develop your component with Visual J++, you will create classes that expose methods. When an ASP script calls your component, your class file is exposed as a COM component by the Microsoft Virtual Machine (VM).
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 and flavor of the ASP Programming model, but to expose it in a way that is more natural for the Java programmer.
WFC includes a class called AspContext. This AspContext class greatly simplifies accessing the ASP built-in objects for Java programmers. The following code snippet demonstrates using AspContext to obtain a reference to the Response object.
// GetResponse.java
import com.ms.iis.asp.*;
import com.ms.mtx.*;
public class wfcgetResponse
{
public boolean myResponse()
{
Response myResponse = AspContext.getResponse();
myResponse.write("Hello there");
return true;
}
}
If you develop with Visual J++ 1.1 you will need to register the class that implements your component. You register the class with the javareg.exe tool, which is installed with the VM. Visual J++ 6.0 eliminates the need to register the class with javareg, since you can implement your class as a dynamic link library (DLL). If you implement your class as a .dll file, it will be registered automatically when you build the component. If you choose to implement your component as a .class file you will still need to register it. Visual J++ 6.0 provides a new tool, vjreg.exe, for registering java class files.
One unique aspect of implementing with Java is that you can create an instance of a your class by using a Java Moniker. A Java Moniker is a name that describes the path of the Java class file to the VM. 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. For example, if a component is stored at the location C:\MyClasses\Response.class
, the following script would create an instance of response
.
<%
GetObject ("Java:C:\MyClasses\Response.class")
%>
Note Objects created by calling GetObject instead of Server.CreateObject cannot access the ASP built-in objects through ObjectContext and cannot participate in a transaction.
For complete sample components that use ObjectContext to access the ASP built-in objects, see Developer Samples.