Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coonecting to a website with default browser

Status
Not open for further replies.

Leighton21

Technical User
Dec 17, 2001
83
AU
Hi I am kind of new to Java, anyway I have written an application that displays information from a database in a table. I wanted to be able to right click on a particular entry and then connect to a website based on the key field. Does anyone know how to start the the users default browser, from within my application (eg netscape) and then connect to the specified site

Cheers
 
/*
* Author : Deepak Singh Bisht
*/

package com.infogain.adapter.cgui;

import java.io.*;

public class CGUIInvokeBrowser
{
// The default system browser under windows.
private static final String WIN_PATH = "rundll32";
// The flag to display a url.
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";

/**
* Display provided URL in systems default browser
* @param String url.
*/
public static void displayURL(String url)throws Exception
{
boolean windows = isWindowsPlatform();
String cmd = null;
try
{
if (windows)
{
cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Process p = Runtime.getRuntime().exec(cmd);
}
}
catch(IOException x)
{
// couldn't exec browser
throw new Exception("Could not invoke browser, command=" + cmd);
}
}

/**
* Check if the current OS is windows platform.
* @return boolean.
*/
public static boolean isWindowsPlatform()
{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith("Windows"))
return true;
else
return false;

}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top