Opening an URL from a JAVA application

hi,
iam new to Java.
Currently iam designing a simle GUI which takes input(URL) from user in a test field and has a button.Upon clicking button i want to open the webPage specified by that URL in a default webBrowser.
How can i do that(opening webPage)?
advanced thanks for your help.
vd.rach

getting an error on that line as follows: "unreported
exception; must be caught or declared to be thrown".exec() throws IOException so catch it.
try {
Runtime.getRuntime.exec(...);
catch(IOException e) {
System.err("Cannot launch the browser: " + e.getMessage());
}On the side note: I found javaworld's [url http://www.javaworld.com/javatips/jw-javatip66_p.html]solution most useful in serving this purpose in a project, even though its a little bit platform specific.

Similar Messages

  • Displaying a URL from a Java application

    Hi,
    I recently implemented a test Java application based on Steven Spencer's Java Tip 66: "Control browsers from your Java application" (http://www.javaworld.com/javaworld/javatips/jw-javatip66.html). Spencer's example tests for the current operating system, sets some constants based on the OS that it finds, and then calls the Runtime.getRuntime( ).exec( ) method. During the call, you can pass either a file:// or http:// URL. I can get the example to work perfectly given a file:// URL but have limited success supplying the http:// URL. When I supply a specific http:// URL such as "http://someserver/somedir/testfile.htm" the browser returns a "Cannot open URL" error. However, if I supply a URL that does not resolve to a specific HTML file, such as "http://someserver/somedir", and the directory has either a "index.htm" or "index.html" file, the application works fine. I would like to be able to pass an http:// URL that resolves to a specific HTML file. I am trying to implement context-sensitive help from within a Java application. I am testing this on a machine running Windows 2000 and using Microsoft's IE 5.x browser. Any help would be appreciated.
    Thanks,
    Scott Rifenbark

    The browser doesn't know that it was started by this Java code, you know. So you are asking why your browser (Internet Explorer) doesn't let you get at specific files. The answer is, that isn't how the Internet works. A URL is a "Uniform Resource Locator" (or something a lot like that). It locates a resource on the Internet. This resource may or may not be a file, but as the client you have no way of knowing whether what you get in response to that is a file on the server or whether it has been generated by some CGI program there.
    When you send an http:// URL to a web server, it looks at what you have sent and goes through its configuration files. Using this it translates that URL into either a file on the server (which it returns to you) or a program which it calls to return data to you. If it was a file, its local name on the server doesn't have to be related in any way to the contents of the URL.
    It sounds like you are planning to be the one setting up those files on the server, though. If that's the case, you have to configure the server appropriately for your needs.

  • Opening a URL from a Java Program

    Hi all,
    Can I open Internet Explorer and invoke a URL from a Java Program. If it can be done, could someone please give a code for that.
    Thanks in advance.

    Did you try it like "start \"http://java.sun.com\""
    or maybe
    "start 'http://java.sun.com'"I've no idea whether that will work, but it would be the first thing I'd try.

  • How to open JSP session from a java application or an applet?

    Hi,
    My problem is a bit challenging (at least for me) and its not about JSP but it is about a web application..
    I couldnt find a better place to post this question I am sorry if this is not the right place to post it..
    I need to enable users log into my website by checking username and password and reading and checking the data from a usb device located in client computer.
    I can read from the device thorough JNI using the third party DLL file for the device... I have no problem with that..
    Since I need to make native calls I am planning to develop a java application so I let the users open the application using web start.. Once my application is running on client side after reading the device and getting login password information (assuming login information correct), How can I open a web session for the that spesific user and a web browser and let the user browse the web site on his/her own session?
    I would appreciate any guidance..
    Thanks..

    add the values in the header using...
    response.addHeader("userNmae","XXXX");use it in all ur pages like say..
    if(!request.getHeader("userName")!=null && request.getParameter("userName").equlas(""))
    String username=request.getParameter("userName");
    }

  • 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 open browser window from standalone Java Application???

    Is it possible to start Internet Explorer from non-applet application?

    Something like that could maybe help:
    Runtime.getRuntime.exec("iexplore http://www.google.com");
    but it's not platform independent + I couldn't let it work in that way. It only worked with Runtime.getRuntime.exec("c:\\windows\\....\\iexplore.exe http://www.google.com");
    But it's surely not platform independent.
    So the answer is in fact 'I don't know'.
    And if you ask why am I writing all that then, the answer is 'I don't know' too.
    And if you ask why...

  • How to open a url from a desktop application

    Hi this may seem like a very easy question but all the topics online point to the following code....
    var url = "http://www.adobe,com";
        var urlReq = new air.URLRequest(url);
        air.navigateToURL(urlReq);
    However when I try to use this I keep getting an 1120 error saying that a definition for air could not be found.
    Can someone please give me some fast direction?

    I tried your suggestion...
    Then after hitting myself in the head multiple times I came to say thanks
    I really appreciate the help.

  • Want to open a URL from java application?

    I want to open a URL (say http://yahoo.com) from my java application without using servlets. PLzzz help asap

    Include these packages:
    import java.net.*;
    import java.io.*;
    Proxy Setting If any:
    //getProxy your proxy address default "No Proxy".
    if (!getProxy.equals("No Proxy"))
    System.getProperties().put("proxySet","true");
    System.getProperties().put("proxyHost",getProxy);
    System.getProperties().put("proxyPort","80");
    Main code:
    URL url = new URL("http://mail.yahoo.com");
    URLConnection connection1 = url.openConnection();
    String filetext=postURL(connection1);
    Function postURL:
    public String postURL(URLConnection connection)
    try
    BufferedReader httpResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String line = new String();
    StringBuffer buffer = new StringBuffer();
    while((line=httpResponse.readLine())!=null)
    buffer.append(line);
    httpResponse.close();
    return buffer.toString();
    catch(Exception e)
    System.out.println("Error:"+e);
    return "Error4" ;

  • 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());
    }

  • How to call pdf forms developed in ABAP from WD Java application?

    Hi
    I have a web dynpro ABAP application that that is responsible for generating PDF forms for all other applications (WD ABAP and WD Java).
    How can I call the pdf forms generated by the WD ABAP application from WD Java application in a separate window?
    These forms are to be called on click of a "Print" button. Also, these forms are non interactive.
    Kindly let me know if you need any other information.
    Regards
    Vineet Vikram
    Edited by: vineet vikram on Jun 24, 2009 7:28 AM

    in addtion to Nikhil's response. you can write following code on action of print button:
        IWDWindow window = wdComponentAPI.
            getWindowManager().createExternalWindow(
                  "<ABAP Application URL>",
                  "<Title for window>",
                  false);
       window.open();
    to Close the application, you can use the window close or u can fire an event to close current window.
    Abhinav

  • Control browser properties from a java application while launching a browse

    How to control the properties of a browser when it is launched from a java application?
    I am using the command " Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url); " to launch the browser. The syntax of "exec" command is "public Process exec(String command,String[] envp) throws IOException". I would like to know whether we can give the arguments in this command to control the browser properties.
    If you know any other option by which we can open a URL in a controlled browser, please share it.
    Thanks in advance :).
    Surekha_Venugopal

    Hi All,
    I have found a solution to control browser parameters from Java applications.
    1. Create an intermediate HTML file at runtime which contains Javascript to launch a browser. Pass the parameters like the URL and browser control parameters to the Javascript of this HTML file.
    2. Open this HTML file and invoke the javascript while loading the file. Javascript will launch the required URL in a controlled browser.
    3. Close the intermediate HTML file.
    Limitation:
    1. There will be a flickering of windows.
    2. Applets will have permission issues with the above solution. For applets a better solution is JSobject. No need of an intermediate file here.
    Hope this will be useful for someone. :-)
    Cheers,
    Surekha_Venugopal

  • 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.

  • Can we control the top level navigation in portal from a java application

    Hello,
    I am having a scenario where User logged in to portal and assigned with 2 roles (HOME , ISA(Java application)). When user opened a form in ISA (Java application) and tried to enter the data in form and moved to another tab (e.g. HOME) in top level navigation.
    When user come back to ISA (Java application) TAB , we show the page where he left earlier. I would like to know if user click any other TAB in top level navigation (Role assigned to him) while working on a page in ISA(Java application) is there any way we can catch that event before he leaves from ISA (Java application JSP page) to other TAB?
    How can we control the top level navigation events in the portal from a java application .Since Top level navigation is seperate par file.
    Thanks,
    RN

    Dear Rajesh,
    Top Level and detailed navigation values comes with iteration in the respective par file.
    Please check the par file and based on the value (i.e tab name) selected, you can write your code.
    Best Regards
    Arun Jaiswal

  • Manipulate Indesign cliente from a Java Application

    Hello, I need to manipulate Indesign client(open/close documents, create menus, tables, set colors etc... ) but I need to do that from a Java application. Is it possible? I was searching on google about it, even in Adobe's site, but the only way I found was thought Javascript, VbScript or AppleScript.
    Thanks in advance!
    Rafael

    I can control inDesign from Python or shell scripts on osx via `osascript` This is roughly how it works.
    My 'master' program runs shell command `osascript -e "tell Indesign blahblah end tell" /path/to/temporary.jsx`  
    `osascript` tells Indesign to execute "/path/to/temporary.jsx" as javascript
    If all goes well, the value of last expression  in .jsx is returned by `osascript` (serialised JSON works great for this)
    Sorry I'm vague on real life code, but this is my home machine so it's not in my reach.
    I realise it's an ugly hack. Main cons follow:
    quotes have to be escaped couple of times so the result is messy and prone to errors (luckily it's one-off code that sits hidden behind main interface)
    debugging this chain is nightmare (especially with my nigh-zero knowledge of applescript)
    so far it's mac only (I suspect same thing can be achieved on Windows machine with VBS)
    one cannot avoid writing lots of temporary files to the system. (luckily for me, it's only deployed on machines under my control, so the temp files are written to /tmp which is mounted on ramdisk)
    The only pro I can think of is that it works. Whole comlexicity is wrapped in one python module, which I only see when squashing the bugs.
    Marcel

  • Opening a document from a Java app

    I need to open a document from my Java app. It is a .rtf file and I would like it to open with the system associated application for rtf files. How should I do that?
    I have tried to figure out the Runtime.exec(), but it doesn't do what I need. I have been able to open Notepad or WordPad (oh, yes, I am on a Win XT system) by specifying them in the exec function, but I can't find info on how to let the system choose the program.
    Thanks for your help.
    Wayne

    Take a look at the JDIC project
    https://jdic.dev.java.net/
    In particular the org.jdesktop.jdic.filetypes.AssociationService class
    https://jdic.dev.java.net/nonav/documentation/javadoc/0.9/index.html

Maybe you are looking for

  • No sound on youtube with safari

    No sound on youtube it plays the video but with no sound.

  • Sum Values on 2 Where Clauses

    Hi, sorry to trouble, i havent got any data within a database or anything, just thinking about some work that i might have to do, so trying to get a head start. Was wondering how i would sum values in a column but with 2 where clauses. For example if

  • Connection Manager in 11.1.2

    Hi , I am new to smart view version 11.1.2. I have to add new URL in connection manager. Can somebody help me to do this. I opened shared connections, and searching for action panel to add the URL for HFM. I don't see anything to add the url. "Do i n

  • Question on JSF/JSP mixing issue

    Hello all. We have an JSP application which we are trying to move to JSP. After some thought we decided that these will need to coexist in some parts of the code. Now I have run into an issue as result of these and I am wondering if anyone can help.

  • Check table in data type AFNAM (Name of Requisitioner/Requester)

    Hello, To satisfy a customer's requirement, I changed data type AFNAM so that it would have a search help. The search help name of this data type now points to the ZAFNAM view - this view is based on table ZQQPVS001, where I keep the valid entries fo