Microsoft KB Archive/250538

= PRB: Cannot Call Static and Overloaded Methods from ASP =

Article ID: 250538

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q250538



SYMPTOMS
When you try to call static and/or overloaded methods of a Java class that is registered as a Java COM object from Active Server Pages (ASP) or a Microsoft Visual Basic Scripting file, you may receive the following errors:

For a static method:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'staticMethod'

For an overloaded method:

Microsoft VBScript runtime error '800a000d'

Type Mismatch:'OverLoadedMethodName'

NOTE: The overloaded method has the same method name and the same number of parameters but has different parameter types.

In some cases, you may not receive an error message, but you may notice that only one of the overloaded methods is being called.



CAUSE
For static methods, this problem occurs because static methods are not exposed through the Auto-IDispatch feature.

For overloaded methods, this problem occurs because the Microsoft virtual machine (Microsoft VM) for Java only differentiates between overloaded methods by number of parameters; it does not differentiate based on parameter types. When the overloaded method has the same number of parameters, the Microsoft VM chooses to expose the last method in the .class file through the Auto-IDispatch feature.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  In Microsoft Visual J++ 6.0 or the Microsoft SDK for Java 4.0, create a new Java file named Test.java, and paste the following code: import java.util.Vector; public class Test {

public static void main(String args[]) { Test test = new Test; }

public Test { System.out.println("Constrcutor Called"); }

public static String staticMethod { return "Static Method"; }

public String nonStaticMethod { return "Non-Static Method"; }

public int func1 (int i) { return i*2; }

public int func1(Vector v) { if (v == null) return 0; else return 3; } }                    Copy the resultant Test.class file to your Web server's /Java/Trustlib folder. At a command prompt on the server computer, type the following command to register Test.class as a COM object:

javareg /register /class:Test /progid:Test.1 /typelib:Test.tlb

  Create a new ASP file named Test.asp, and paste the following code: Simple Test <% Set SimpleObj = Server.CreateObject("Test.1") %> <%= SimpleObj.staticMethod%> <%=SimpleObj.func1(123)%> <%=SimpleObj.func1(0)%>  Copy Test.asp to your Web server's Wwwroot folder.</li> Run Test.asp. You receive one of the above-mentioned errors, or you see that only one of the overloaded methods is called.</li></ol>

<div class="references_section">