Open an Explorer from Java

How i can open the default explorer from Java and redirect it to an especific URL?

here is a code snippet that might help.
   public StringBuffer getMainPage (String host, String port, boolean sendToBrowser)
      String       url  = "http://" + host + ":" + port;
      String       line = "";
      StringWriter sw   = new StringWriter();
      // send it.
      post(line, url, sw);
      try
         if ( sendToBrowser )
            // send the default browser to the proper page for this host
            String cmd = "rundll32 url.dll,FileProtocolHandler " + url;
            // System.out.println("cmd =" + cmd );
            Process p = Runtime.getRuntime().exec(cmd);
      catch ( Exception e )
         // e.printStackTrace();
      // System.out.println(" output ='" + sw.toString() + "'" );
      if (sw.toString().length() != 0)
         return sw.getBuffer();
      else
         return null;
   }

Similar Messages

  • Open Internet explorer from Java

    Hi everyone!
    Doew anybody know how to open IOnternet Explorer from Java.I have tried
    String browserCommand = ("\"C:\Program Files\InternetExplorer\iexplore.exe\"");
         URL theUrl=new URL("http://www.yahoo.com/"); // or whatever
         Runtime.getRuntime().exec(browserCommand+ " "+theURL);
    but something goes wrong with the escape characters I use.
    I would be greatful to receive any advice.
    Thanks in advance!

    or...
        private static boolean showInBrowser(String url){
             String os = System.getProperty("os.name").toLowerCase();
            Runtime rt = Runtime.getRuntime();
            try{
                 if (os.indexOf( "win" ) >= 0) {
                      // this doesn't support showing urls in the form of "page.html#nameLink"
                     rt.exec( "rundll32 url.dll,FileProtocolHandler " + url);
                 } else if (os.indexOf( "mac" ) >= 0) {
                     rt.exec( "open " + url);
                 } else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) {
                      // Do a best guess on unix until we get a platform independent way
                      // Build a list of browsers to try, in this order.
                      String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror",
                                "netscape","opera","links","lynx"};
                      // Build a command string which looks like "browser1 "url" || browser2 "url" ||..."
                      StringBuffer cmd = new StringBuffer();
                      for (int i=0; i<browsers.length; i++)
                           cmd.append( (i==0  ? "" : " || " ) + browsers[i] +" \"" + url + "\" ");
                      rt.exec(new String[] { "sh", "-c", cmd.toString() });
                 } else {
                      return false;
            }catch (IOException e){
                 return false;
            return true;
        }

  • How to open Internet explorer from java

    how can one open internet explorer through java and also displays the desired webpage in it.

    p = r.exec(runie);Whenever you use exec on a Runtime object, you need to get an InputStream off the System.err output. If this InputStream is not absorbed in some way, then it can stop the process. The process may not reach its destined finish point. The Java Documentation does not inform you of this, though experience will give you some unanswered questions, such as 'Why does this process never reach the finish point'.
    James

  • How can i open the popup from java class

    Hi,
    Please tell me how can i open the popup from java class.
    I am using jdev 11.1.1.7.0
    I have used the below code which works fine in jdev 2.1 but it will have some errors in 11.1.1.7.0.
    Please tell me some way to do this in all jdev versions.
    Bean obj = (Bean)RequestContext.getCurrentInstance.getExternalContext.getPageFlowScope(“obj”);
    Code for hide pop-up
    FacesContext context = FacesContext.getCurrentInstance();
    String popupId = obj.getPopUpBind().getClientId()
    ExtendedRenderKitService service = Service.getRenderKitService(FacesContext.getCurrentInstance(),
    ExtendedRenderKitService.class);
    String hidePopup = "var popupObj=AdfPage.PAGE.findComponent('" + popupId +
    "'); popupObj.hide();";
    service.addScript(FacesContext.getCurrentInstance(), hidePopup);
    Code to Show pop-up
    StringBuffer showPopup = new StringBuffer();
    showPopup.append("var hints = new Object();");
    showPopup.append("var popupObj=AdfPage.PAGE.findComponent('" +
    obj.getPopUpBind().getClientId() + "');popupObj.show(hints);");
    service.addScript(FacesContext.getCurrentInstance(), showPopup.toString());
    Code need to be added in jsff pop tag
    binding="#{pageFlowScope.bean.popUpBind}
    Variable need to be added in Bean.java
    private RichPopup popUpBind;

    Hari,
    Since you're using a non-public build of JDeveloper, you should be using a non-public forum.
    John

  • Opening HTML file from java GUI

    Can someone please tell me how I can open a HTML file in Internet Explorer from a Java GUI,
    I have an asssignment I am doing for college and I was toying with the idea of putting in helpfiles, for the program, can anyone tell me the easiest way of apcomplishing this???
    Thanks in advance for your help,
    Kaspah

    Although this should answer your question, there are other (cross platform) ways to do what you want. As opposed to your "must have internet explorer" solution. Swing has a built in html viewer you might use, for example. I've been doing some reading on java/xml solutions. I don't consider myself knowledgeable enough (yet) to comment on that solution though. A delimited text file would be another solution. Useing that solution you could treat the file like a set of parrallel arrays on the hard drive and disply your text on pre-formated labels. Anyway, here is a link to you answer......
    http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Runtime.html#exec(java.lang.String)
    Ron_W

  • Unable to open a report from Java SDK

    Hi,
    I am trying to open a report from the SDK in a java application. Here is the code :
    package com.metrixware.test;
    import com.crystaldecisions.sdk.occa.report.application.OpenReportOptions;
    import com.crystaldecisions.sdk.occa.report.application.ReportAppSession;
    import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
    import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
    public class MyBoTest {
    @param args
         public static void main(String[] args) {
             ReportClientDocument myDoc = new ReportClientDocument();
             try {
                  ReportAppSession sess = new ReportAppSession();
                  sess.setReportAppServer("AGIRC-DEMO");
                  sess.initialize();
                  myDoc.setReportAppSession(sess);
                   myDoc.open("rassdk://D:/Document8.rep",OpenReportOptions._openAsReadOnly);
                   System.out.println("Titre du doc : "+myDoc.displayName());
              } catch (ReportSDKException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    but i always get the following error stack (ReportSDKException) on the open method of the doc :
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Impossible de charger le rapport.---- Error code:-2147483123 Error code name:failed
         at com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException.throwReportSDKServerException(Unknown Source)
         at com.crystaldecisions.proxy.remoteagent.s.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.if(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.do(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ClientDocument.open(Unknown Source)
         at com.metrixware.test.MyBoTest.main(MyBoTest.java:22)
    The document is at the right location on my local machine where my test is running. The RAS server is up and running on the CMS.
    Can you help me on this problem.
    Also i have another question. Can you tell me if i'll be able to read through this object the generated SQL select statement of the report.
    Thanks.
    Julien Pignatel

    try the following instead:
    ReportClientDocument myDoc = new ReportClientDocument();
    myDoc.setReportAppServer("AGIRC-DEMO");
    myDoc.open("rassdk://D:
    Document8.rpt",OpenReportOptions._openAsReadOnly);
    Also make sure that on RAS command you have added: -ipport "1566" -reportdirectory "D:/"
    Please note:
    1. Don't need to use ReportApSession class
    2. what do you use Document8.rep, you cannot open a Deski document with RAS. RAS can be used only with crystal reports.
    Hope that helps.
    Best Regards
    Aasavari

  • Opening ADF page from java script

    I am trying to use window.open(url, winName) to open an ADF page from java script.
    I have set the same winName but when i call the window.open method every time it opens up a new window.
    The code is as below:
    <html>
    <head>
    </head>
    <body>
    <script>
    function openwin() {
    window.open("about:blank", "winDocPrint", "width=800,height=600,location=no");
    </script>
    <form action="http://127.0.0.1:7101/RegionRefresh-ViewController-context-root/faces/EnterAndDisplay?_afrLoop=3611588465186&_afrWindowMode=0&_adf.ctrl-state=zoaas2mc3_4" target="winDocPrint" onsubmit="openwin">
    <input type="submit" value="Print Comments Call ADF">
    </form>
    </body>
    </html>
    when I click the button first time, it opens a new window, and keeps opening a new windows on clicking the button again.
    I want it to use the same window that was opened first time.
    Any help would be appreciated.
    Thanks,
    Sandeep M.
    Edited by: user8895611 on Mar 25, 2010 11:44 PM

    Hi,
    you need to keep the window handle reference so you can access the same window
    http://www.irt.org/script/874.htm
    Frank

  • Lauching Internet Explorer from java program

    How can I lauch internet explorer from a java program. I need codes
    Thanks

    What? Is this the Question of the Day or something?
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342624&tstart=0&trange=30

  • Open servlet file from java

    can i open servlet file from java

    do you mean linking to a servlet from java application?
    have you try this?
    URL toServlet = new URL("URLtoServlet");
    URLConnection servletConnection = toServlet.openConnection();

  • Opening Internet Explorer from Air Iframe

    This probably has been answered here before and I apologize if this is a repost but I haven't been able to find an answer that works.
    I have an AIR application that uses an Iframe to connect to a server side page. within that page I need to be able to click a link and launch an Internet Explorer Browser NOT an Air window.
    I have tried several methods and none seems to work,
    does anyone have a sample (both the parent and child frames) that they know works ,
    It will save me allot of headache
    I truly appreciate it 
    Ray

    Thanks but I would need the complete code.
    You see I want to open a particuler page from a link, the link will call, lets say homepage.jsp, I want to include an applet in homepage.jsp that will force the page to open up in a IE window. Is that possible????
    If it is what do I need to do?
    Thanks

  • Opening Internet Explorer from a link w/ applet

    Hi there,
    I was wondering if anybody out there had the code for an applet that will spawn Internet Explorer application and open up a specific address.
    How we want it to work. From a link open a page that will spawn Internet Explorer with the help of the applet. Is it do-able or not?
    A quick response would be great.
    Thanks

    Thanks but I would need the complete code.
    You see I want to open a particuler page from a link, the link will call, lets say homepage.jsp, I want to include an applet in homepage.jsp that will force the page to open up in a IE window. Is that possible????
    If it is what do I need to do?
    Thanks

  • Interenent Explorer from Java

    Hello! I need to post data (for login data) using ie (internet explorer) and then to display the browser to user.
    I use JACOB for browser control and here is the code:
    package testJACOB;
    import java.io.UnsupportedEncodingException;
    import java.net.URLEncoder;
    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.Dispatch;
    import com.jacob.com.SafeArray;
    import com.jacob.com.Variant;
    class IETest
    public static void main(String[] args)
    ActiveXComponent ie = new ActiveXComponent(
    "clsid:0002DF01-0000-0000-C000-000000000046"); //IE
    Object ieo = ie.getObject();
    String path = "http://localhost:3333/portal/Login";
    String postData = "userName=uuu&password=ppp";
    String content = null;
    try
    content = URLEncoder.encode(postData, "UTF-8");
    catch (UnsupportedEncodingException e)
    e.printStackTrace();
    SafeArray sa = new SafeArray(Variant.VariantByte, content.length());
    sa.fromByteArray(content.getBytes());
    Variant[] arg = new Variant[]{
    new Variant(path),
    new Variant(),
    new Variant(),
    new Variant(sa),
    new Variant("Content-type: application/x-www-form-urlencoded") };
    ie.invoke("Navigate2", arg);
    Dispatch.put(ieo, "Visible", new Variant(true));
    Browser sucsefully opens, but I get 'null' post data in my web-app. It seems that web-app got nothing in http-request for post data.
    What is wrong in my code?
    Thank you very much.
    Vladimir.

    WundahWheel,
    learn first how to use interfaces of WebBrowser Control. Here is a simple example. Substitute in NJAWIN WebBrowser Example (file WebBrowserComponent.java)
    public void DocumentComplete(
              Object srcObj,
              DispatchPtr pDisp,
              ObjectRef URL)
              throws COMException {
            System.out.println("DocumentComplete");
            if (doc == null && control != null) {
                doc = new MSHTML.IHTMLDocument2(control.getDocument());
                if (!doc.isNull())
                    DispatchPtr disp = doc.getScript();
                    IHTMLWindow2 win = new IHTMLWindow2(disp);
                    win.showModalDialog("http://www.google.com");
                    doc.addEventListener(
                        HTMLDocumentEvents2.class,
                        new DocumentListener());
                else {
                    doc = null;
                    return;
    }While invoking "DocumentComplete" event you will see WebBrowser Dialog.

  • Opening  browser window from Java Swing

    Hi
    I am trying to open
    1) a word document on the click of a button from a Java-Swing based application running only on windows based system.
    Currently the code uses 'rundll' and calls 'a.doc'
    it requires that the application be installed and run only from a specific location in the windows' system.
    i would like to modify the code in one of the following ways
    1) open the word doc irrespective of its location and that of the executable jar which is trying to open this file
    2) upload the word document to a website and direct the application to open that webpage on button click, etc
    i believe that the latter may be simple but i do not have any idea about how to go about it
    i would appreciate some guidance about it.

    Hi,
    I was trying to run the code, for embeding the mozilla web browser in my java application which is running at linux fedoracore2. I set all the environment variables, like MOZILLA_FIVE_HOME and LD_LIBRARY_PATH. I can able to compile successfully but if i run the code, i got the error message like this
    Exception in thread "main" java.lang.Error: Untranslated exception
    at sun.nio.ch.Net.translateToSocketException(Net.java:63)
    at sun.nio.ch.Net.translateException(Net.java:79)
    at sun.nio.ch.Net.translateException(Net.java:85)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:61)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52)
    at org.jdesktop.jdic.browser.MsgClient.<init>(Unknown Source)
    at org.jdesktop.jdic.browser.NativeEventThread.<init>(Unknown Source)
    at org.jdesktop.jdic.browser.WebBrowser.<clinit>(Unknown Source)
    at IEInJava.main(IEInJava.java:8)
    Caused by: java.net.SocketException: Unresolved address
    at sun.nio.ch.Net.translateToSocketException(Net.java:55)
    ... 8 more
    Caused by: java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:30)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:115)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
    ... 5 more
    Thats the error.
    I could not find out, where i had made the mistake, i need help. Any suggestion and comments are most welcome. Thanks.

  • 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" ;

  • Open a program from java

    Hi everybody,
    I have a java class which can insert a BLOB into DB2 mainframe and a java class which can select a BLOB from DB2 mainframe. When I select my BLOB, I write it into a file.
    I would like after write my file, open it with the good application, my BLOB(file) can be jpg, doc, xls, ...
    Is it possible open the good application from my java application?
    Thanks

    Yes, it's possible. Look into the Runtime.getRuntime().exec() method.

Maybe you are looking for

  • Multi-mapping 1:n - 1:1

    Hi, We are using multi-mapping in a file-to-file interface. When we have 1:n everything is ok, but when we have 1:1 we have this error: Success The message status set to DLNG. Error Unable to find channel ID Error Delivery of the message to the appli

  • How good is  the iMac's internal DAC?

    Assuming it has one of course Currently i have my iMac connected straight to an amp and then speakers using phono leads but  was wondering whether I would get much better sound quality if I connected a USB DAC between the iMac and amplifier ,The soun

  • System clipboard, AWT TextAreas, and JTextAreas

    This code makes a JApplet with a Swing JTextArea and an AWT TextArea. The JTextArea won't accept pasted text that was copied from another application. The AWT TextArea will. Why is this, and how can I get a JTextArea to accept pasted input? import ja

  • Export for actionscript - Not in first frame

    Just a simple question. Don't need to know if it works or not I have tested it. What I want is to understand. Here it is: If I use the Export for actionscript and I unselect the Export in first frame, the item that will be linked by the ID in the lib

  • How can i save my 1yr history ?

    I have firefox 15.1 on my Mac OSX 10.6 and i need to save the firefox history for 1yr because i will install new OS so i need to save the history, how can i do that?? Thanks