1.方法一,用java的api--uri使用默认浏览器打开url
public class TestSystem {
public static void main(String[] args) {
//判断当前系统是否支持Java AWT Desktop扩展
if(java.awt.Desktop.isDesktopSupported()){
try {
//创建一个URI实例
java.net.URI uri = java.net.URI.create("http://www.baidu.com/");
//获取当前系统桌面扩展
java.awt.Desktop dp = java.awt.Desktop.getDesktop();
//判断系统桌面是否支持要执行的功能
if(dp.isSupported(java.awt.Desktop.Action.BROWSE)){
//获取系统默认浏览器打开链接
dp.browse(uri);
}
} catch(java.lang.NullPointerException e){
//此为uri为空时抛出异常
} catch (java.io.IOException e) {
//此为无法获取系统默认浏览器
}
}
}
}
2.方法二
//使用默认浏览器打开
Runtime.getRuntime().exec("rundll32url.dll,FileProtocolHandlerhttp://www.baidu.com");
1.跳转到指定url
response.sendRedirect("http://www.baidu.com/");
2.获取进去servlet的当前页面url
例如从“http://localhost:8080/crm/index.jsp”通过表单或者链接进入servlet,如何获取到“http://localhost:8080/crm/index.jsp”
String url = request.getHeader("referer");