Java GUI界面打开网页html的两种方式:
1、调用cmd 打开IE浏览器
public static void main(String[] args) throws IOException {
String str = "cmd /c start iexplore http://localhost:8080/Search/login.jsp";
try {
Runtime.getRuntime().exec(str);
} catch (IOException e) {
e.printStackTrace();
}
}
2、直接打开默认浏览器
public static void main(String[] args) {
try {
String url = "http://localhost:8080/Search/login.jsp"
java.net.URI uri = java.net.URI.create(url)
// 获取当前系统桌面扩展
java.awt.Desktop dp = java.awt.Desktop.getDesktop()
// 判断系统桌面是否支持要执行的功能
if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
// File file = new File("D:\\aa.txt")
// dp.edit(file)
dp.browse(uri)
// dp.open(file)
// dp.print(file)
}
} catch (java.lang.NullPointerException e) {
// 此为uri为空时抛出异常
e.printStackTrace()
} catch (java.io.IOException e) {
// 此为无法获取系统默认浏览器
e.printStackTrace()
}
}