Open URL in Web Browser from a Java Application

Hi,
I have an HTML document that I want to load in a browser window by clicking on a button in my java GUI application.
Any suggestions?
Thanks.

You can use the Process class to start the web browser with the proper command line arguments (depends on the web browser though). Or on windows, you can have your program create a batch file with the code start url (where [url] is your url), and this will open the default web browser when run (again you must run it with a Process).

Similar Messages

  • Launch a default web browser from my java application

    Hello,
    I have been trying to launch my default web browser from my java application, but am unable do it. Right now, I am using ---- "Runtime.getRuntime().exec("cmd /c start <url>"); to launch my webbrowser. It launches the browser but displays the command prompt for a second or so, and then replaces my already existing page with the new url.
    Is there any way for me to launch the url in a completely new browser each and every time. And I don't want the command prompt to show up for a sec. Please help...!
    Thanks in advance.
    -BusyBusyBee

    If by any chance your application is an Applet, you can use this to open a new browser window:
    getAppletContext().showDocument(new URL(theUrl), "_blank");
    But, you probably would have specified if that were the case. Oh well. Hope it helps someone!
    -sheepy.

  • How can I launch a web browser from my Java application?

    I've reed about this at Question of the Week (http://developer.java.sun.com/developer/qow/archive/15/index.html). It doesn't work for me. I'm running win2000 and trying:
    try {
    Runtime.getRuntime().exec("start iexplore http://java.sun.com");
    } catch (Exception e) {
    System.out.println( e.getMessage() );
    I get:
    CreateProcess: start iexplore http://java.sun.com error=2
    What's wrong?

    This function will launch the default browser under Windows.
    public static void displayURL(String url) throws IOException   {
        String cmd = null;
        Process p;
        try  {
            String os = System.getProperty("os.name");     
            if (os != null && os.startsWith("Windows")) {
                if (os.startsWith("Windows 9") || os.startsWith("Windows Me"))  // Windows 9x/Me
                    cmd = "start " + url;
                else // Windows NT/2000/XP
                    cmd = "cmd /c start " + url;
                p = Runtime.getRuntime().exec(cmd);     
        catch(IOException x)        {
            // couldn't exec browser
            System.err.println("Could not invoke browser, command=" + cmd);

  • How do i Hyperlink to a web page from a java application?

    How do i Hyperlink to a web page from a java application using internet explorer as my default web browser?

    It's very simple.You can start any Application with the class Runtime. The command is an array consisting of the path of .exe and the file to be open.
    String [] cmd={path of IE+Filename.exe,"URL of your website"}
    try
    Runtime.getRuntime().exec(cmd);
    catch (Exception e)
    System.err.println(e.toString());
    }

  • Attempting to launch a help browser from a java application

    I am currently investigating being able to view help html files through launching a browser from my Java application. I have come across the java.lang.Runtime and java.lang.Process classes which allow me to launch a browser like Netscape or Explorer and bring up a html file to view.
    What I want to do is launch the browser and bring up an html index file as well as the required html help file every time a user would like to use the help for my application.
    Is this possible using the other exec commands. If so, how? Is there somewhere I can find a user guide for Netscape and Explorer commands in order to send additional commands to the browser in order to do this.
    Thanks.

    Good news is it must be possible because VisualAge does it but I don't know how.

  • Calling a web service from a Java application

    Does anyone have sample code showing how to call a web service over from a Java application? I'm deploy to HP-UX and seeking out the most standard and reliable approach.
    Thank you in advance.

    Keith,
    Download JWSDP 1.2, look at the tutorial for JAXRPC, especially
    the client portion.

  • Opening a web browser from a Java prog

    I am writing a pseudo-wordprocessor, and would like to be able to set a JMenuItem's action so that when a user clicks it, the system default web browser opens with the web page that I have selected. (e.g. open up a "Help" web page).
    The JavaDoc/tutorial doesn't seem to have anything on running external programs from within a Java program, so does nayone know how this is done?

    If you don't want to go the Java Runtime route and make your program a bit more cross-platform friendly, you could use the JEditorPane to render an html page directly in your application (assuming of course that you're using Swing).

  • Open default browser from a java application

    How is possible to make a java application that open an html file in the default browser ?
    Thankyou
    [email protected]

    You can do that by running the command "start <url>", for example using Runtime.exec().
    Runtime.getRuntime().exec("start http://java.sun.com");Jesper

  • How to launch the default web browser from a java app on MAC

    I know, this topic has been brought up over, and over, however I couldn't find info regarding MAC environments. I don't have any former experience with MAC, but now I'm getting desperate for a solution. I need to be able to pop up the default browser showing a certain URL on MAC/OS. Any clue would be appreciated.
    thanks,
    m. berdan

    I wrote libraies that will do this:
    http://ostermiller.org/utils/Browser.html
    I also keep a list of other resources to help you out:
    http://dmoz.org/Bookmarks/D/deadsea/Java_Help/Web_Browser/
    Stephen

  • Launching a Browser from a Java Application

    I want to open an HTML page in the "default" browser. I know how to run commands so I could open IE or Netscape but I want to open a browser without having to know what browser they have installed. It would be nice if there is something that isn't platform dependent. Is this possible?

    It would be nice if there is something that isn't platform dependent. So you've seen the java tip
    http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
    I don't think it's that easy to do what you want so that it is portable... sad that the current API doesn't have great support for programs written in other languages than Java.

  • Closing browser from a java application

    I have an applet having a button Save on it. I am calling a javascript function of closing the browser. But if i click it, a built in message comes to confirm the closing of browser having two opitons Yes and No. Is there any possibility that the browser closes without showing this message?

    May this is the wrong forum to post this message. However you could avoid that close-dialog by setting an opener
      function closeWindow() {
        window.opener="x";
        window.close();
      }So you can fake an self-opened window.
    The behaviour depends on used browser. So this should work for IE and Opera but not for Netscape...
    br
    karl

  • Open a Windows help file from a Java application

    Help!!! Final project due Wednesday. Our project was to re-create the Windows 2k calculator, which we pretty well did, with the exception of accessing the help file. I think I am close but not sure how to deal with the compiled HTML files that Windows uses for its help utilities. The following code makes the calculator itself pop up.
    public void helpFilePopUp ()
    try
    String command = "calc";
    Process child = Runtime.getRuntime().exec(command);
    catch (IOException e)
    System.out.println("Object not found.");
    }//end of method
    Thanks in advance A.

    Maybe I didn't understand your problem correctly.
    If you just want to start the windows help with the calculator helpfile then your command should look like
    "WINHLP32.EXE c:\windows\help\calc.hlp" and not "calc".

  • Any new ideas for launching web browser from application

    I have searched the forums trying to find a new way of launching a web browser from a java application. The problem I am having is that on Unix and Linux systems, at least the variety I have access to (not quite sure on what that variety those are as they are not my systems or systems I control), the common method of using Runtime.getRuntime().exec(STRING) with either netscape or mozilla does not work. While using the Runtime.exec method is not the same as a console, I did try on these systems "netscape + A_WEB_ADDRESS" (or mozilla) and it did launch the respective browser with the page, so it appears that at least from the console level, those commands are valid.
    All the forums seem to say that the Runtime.exec method is the way to go. All the source code I have found through links from the forum say the same thing. I have voted on this bug:
    http://developer.java.sun.com/developer/bugParade/bugs/4210168.html
    and the feedback there does seem to indicate that there is similar trouble out there. Below is the code I am using. It does work on Win2000,XP, and Mac OSX. The application is not supported on earlier systems, and as it stands it will not work on Win 95,98, nor ME. Only small modification should be needed for work on those OSs, but as I no longer personally use those OSs, I cannot be sure.
    private void openNativeBrowser(String url) {
    // not the browser itself is started, i only call something like
    // start http://www.javasoft.com
    // and then the standardbrowser will be started ...
    StringBuffer call = new StringBuffer();
    System.err.println(System.getProperty("os.name"));
    System.err.println(System.getProperty("user.dir"));
    try {
    // which OS ?
    String operatingSystem = System.getProperty("os.name");
    // how to call the OS
    if (operatingSystem.toLowerCase().indexOf("windows") > -1)
    call.append("cmd /c start ").append(url);
    else
    if (operatingSystem.toLowerCase().indexOf("mac") > -1)
    call.append("open ").append(url + " &");
    else if(operatingSystem.toLowerCase().indexOf("linux") > -1)
    // use Script 'netscape'
    call.append("mozilla ").append(url).append(" &");
    else
    call.append("netscape ").append(url).append(" &");
    System.err.println(call.toString());
    // start it ...
    Runtime.getRuntime().exec(call.toString());
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    As I said, if you have a new way to call the broswer that seems to work on either Unix or Linux, please post it, point to it, or explain it.
    Aaron

    there is a shell script on Linux called htmlview that you can launch like this:
    String[] cmd = {"htmlview", "http://java.sun.com"};
    try {
        Runtime.getRuntime().exec(cmd);
    } catch (IOException ioe) {
        // do something
    }which will open the default browser. Don't think this is available on other *NIX though, although the script itself would probably work so you could include it with your app (/usr/bin/htmlview).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to open a web browser from java

    Hi
    Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
    Thanks.
    Hung.

    You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
    The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
    import java.lang.Runtime;
    public class Explore{
    public static void main(String[] args) {
    try{
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
    }catch (Exception e) {
    System.out.println("Exception: " + e);

  • How to launch a web browser from a MAC java app

    I know, this topic has been brought up over, and over, however I couldn't find info regarding MAC environments. I don't have any former experience with MAC, but now I'm getting desperate for a solution. I need to be able to pop up the default browser showing a certain URL on MAC/OS from a java application. Any clue would be appreciated.
    Thanks a lot,
    michael berdan

    I wrote libraies that will do this:
    http://ostermiller.org/utils/Browser.html
    I also keep a list of other resources to help you out:
    http://dmoz.org/Bookmarks/D/deadsea/Java_Help/Web_Browser/
    Stephen

Maybe you are looking for