Help and Support
 

powered byLive Search

HOWTO: Using a Java Class with Active Server Pages

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:167941
Last Review:November 14, 2005
Revision:2.5
This article was previously published under Q167941

SUMMARY

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

Back to the top

MORE INFORMATION

The following steps show how to use a Java Server Object with ASP:
1.Install the Microsoft virtual machine (Microsoft VM) (Build 1518 or newer) (Microsoft Visual J++ 1.1 comes with 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 VM you have in your system. You can download the latest VM from
http://www.microsoft.com/mscorp/java/ (http://www.microsoft.com/mscorp/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: You do not have to 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 Microsoft VM if you copy over a preexisting class file. To restart the Microsoft VM on the server side, go to Microsoft Internet Service Manager (IIS) 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 Visual J++ 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. Make sure that the directory that the file is in has EXECUTE access. You can check this in the Microsoft Internet Service Manager. A simple ASP file would appear as follows:
   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.

Back to the top

REFERENCES

For additional information about obtaining the latest version of the Microsoft VM, click the article number below to view the article in the Microsoft Knowledge Base:
163637 (http://support.microsoft.com/kb/163637/EN-US/) INFO: Availability of Current Build of Microsoft VM
For more information about Visual J++ and the SDK for Java, visit the following Microsoft Web sites:
http://www.microsoft.com/mscorp/java/ (http://www.microsoft.com/mscorp/java/)

Back to the top


APPLIES TO
Microsoft Java Virtual Machine

Back to the top

Keywords: 
kbfaq kbhowto KB167941

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.