Microsoft KB Archive/252030

= How To Invoke Internet Explorer from Java and Navigate to a URL =

Article ID: 252030

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q252030



SUMMARY
This article describes how to invoke Microsoft Internet Explorer from Java and navigate to a URL.



Steps to Invoke Internet Explorer
 In Microsoft Visual J++ 6.0, create a new empty project. Add a new class to the project named Navigate.java.  Paste the following code into the file: import com.ms.com.*; import shdocvw.*; public class Navigate {     IWebBrowserApp testBrowser = null;

public static void main( String args[] ) {         IWebBrowser2 testBrowser = (IWebBrowser2)new InternetExplorer; testBrowser.getApplication; testBrowser.setVisible(true); Variant var = new Variant; var.putEmpty; testBrowser.Navigate("http://www.msdn.microsoft.com",var,var, var, var); }  }                     Click Project, and then click Add COM Wrapper to add the Component Object Model (COM) wrappers for the Microsoft Internet Controls (Shdocvw.dll). Compile and test the new project.

NOTE: The IWebBrowser2 interface replaces the IWebBrowserApp and IWebBrowser interfaces.

NOTE: In this example, the last four parameters of the Navigate method are optional. As a result, we create a Variant and call its putEmpty method to act as the arguments that we are not supplying.

