HOWTO: Using a Java Class with Active Server Pages

Last reviewed: January 29, 1998
Article ID: Q167941
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java, version 1.0, 1.1

SUMMARY

This article demonstrates how one can use a Java class as an ActiveX server side object with Microsoft Active Server Pages (ASP).

MORE INFORMATION

The following steps show how to use a Java Server Object with ASP:

  1. Install the Microsoft VM for Java build 1518 or newer (Visual J++ 1.1 comes with a build 1513). You can check the version of the Msjava.dll in your windows/system or winnt/system32 directory to verify what build of the Microsoft Virtual Machine you have in your system. You can download the latest Virtual Machine from http://www.microsoft.com/java.

  2. Create your Java class, which will be created as a COM object. For example:

          // SIMPLE.JAVA-------------
          public class Simple
          {
    
             public int SimpleFn ( int x )
             {
                return x * 2;
             }
          }
    
    

  3. Compile the .java file into a .class file, that is:

         jvc simple.java
    

    NOTE: This does not require that you use the Microsoft compiler for Java,

           JAVAC works just fine.
    

  4. Copy the resulting .class file into the %windir%\java\trustlib or %windir%\java\lib directory of the server machine. Note that you may have to restart the Virtual Machine if you copy over a preexisting class file. To restart the Virtual Machine on the server side; go to Microsoft Internet Service Manager and stop and then restart all three IIS services (that is, www, gopher, ftp).

          copy simple.class \winnt\java\trustlib
    

  5. Register your Java class as a COM object on the server machine using the JavaReg utility (available with VJ++ or the Microsoft SDK for Java). This can also be done manually or by a setup program, "javareg /register" is only creating registry entries:

          javareg /register /class:Simple /progid:Simple
    

    The /class: argument is the name of the .class file in your trustlib or lib directory. The /progid: is the name that you will use in CreateObject() to create your COM object.

    Now your Java class is registered as a COM object and ready to use from Active Server Pages.

  6. Create an .asp file in an HTTP shared directory on your computer. Be sure that the directory the file is in has EXECUTE access. You can check this in the "Microsoft Internet Service Manager." A simple ASP file would look like:

          SIMPLE.ASP-------------
          <html><body>
          <h1>Simple Test</h1>
    

    The result from SIMPLE is:

          <% Set SimpleObj = Server.CreateObject("Simple") %>
          <% = SimpleObj.SimpleFn(5) %>
          <hr>
          </body></html>
          ------------------------
    

  7. Open your web browser and point to YOUR_MACHINE/simple.asp.

REFERENCES

For additional information on how to find the latest Microsoft Virtual Machine, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163637
   TITLE     : Availability of Current Build of Microsoft VM for Java

Additional information and Active Server Pages samples can be found at http://www.microsoft.com/IIS/UsingIIS/Developing/Samples/

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: ASP java server com CreateObject

Keywords : JCOM
Technology : kbInetDev kbole
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.