日期:2014-05-20  浏览次数:20898 次

如何在Linux环境下,使用Java打开默认浏览器
如题

------解决方案--------------------
我不了解你的问题,但Applet中可以这样实现

URL url = new URL(applet.getDocumentBase(), "http://....");
applet.getAppletContext().showDocument(url,"Test" );
------解决方案--------------------
楼主有点不明白你的意思。
Java code

import java.lang.reflect.Method;
import javax.swing.JOptionPane;
/**
* java打开浏览器
* @author wzf
* 2008-7-23 上午09:16:23
*/
public class URLOpener
{
/**
  * test
  * @param args
  */
public static void main(String args[])
{
  openURL("");
}
/**
  *
  * @param url
  */
public static void openURL(String url)
{
  String osName = System.getProperty("os.name");
  try {
   if(osName.startsWith("Mac OS"))
   {
    //doc
    Class fileMgr = Class.forName("com.apple.eio.FileManager");
    Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[] {String.class});
    openURL.invoke(null, new Object[] {url});
   }
   else if(osName.startsWith("Windows"))
   {
    //Windows
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
   }
   else
   {
    //assume Unix or Linux
    String[] browsers = {
      "firefox", "opera", "konqueror",
      "epiphany", "mozilla", "netscape"};
    String browser = null;
    for(int count = 0; count < browsers.length && browser == null;count++)
    {
     if(Runtime.getRuntime().exec(
       new String[] {"which", browsers[count]}).waitFor() == 0)
     {
      browser = browsers[count];
     }
    }
    if(browser != null)
    {
     Runtime.getRuntime().exec(new String[] {browser, url});
    }
   }
  }
  catch(Exception ex)
  {
   ExpWork.doExp(ex);
  }
}
}

------解决方案--------------------
探讨
java本来就是跨系统的,任何系统装个jvm都是一样的,不存在在那个系统环境下

------解决方案--------------------
方法有很多的:
Java code
public static void main(String[] a) {
        try {
            URI uri = new URI("http://www.baidu.com");
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }
            if (desktop != null)
                desktop.browse(uri);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

------解决方案--------------------
路过 顶一下
------解决方案--------------------
帮顶,貌似最常见的是Runtime和DeskTop这两种了,DestTop需要jdk1.6支持,不知道在java中使用脚本行不行,等高手
------解决方案--------------------
学习了~~~