日期:2014-05-18  浏览次数:20637 次

怎么用JSP来判断目前网络是否通畅(可以上网)?
怎么用JSP来判断目前网络是否通畅(可以上网)?

------解决方案--------------------
ping网关吧
------解决方案--------------------
HttpURLConnection http;
String youURL= " ";//输入一个网站,判断能否连接上。
try {
URL url = new URL(youURL);
http = (HttpURLConnection) url.openConnection();
}
catch (IOException ex) {
ex.printStackTrace();
System.out.println( "建立网络连接发生错误: " + ex.getMessage());
return null;
}
if (http.getResponseCode() != 200) {
System.out.println( "网络连接失败 ");
return null;
}