后面检测网站是否挂掉

用ajax发送同步请求来判断网站是否挂掉不能解决跨域访问的问题。。

可以在后台用定时任务去检测试

代码如下:

publicvoidhttpConnetion(StringurlStr,AsformwebSitewebSite){

URLurl=null;

try{

url=newURL(urlStr);

URLConnectionURLconnection=url.openConnection();

HttpURLConnectionhttpConnection=(HttpURLConnection)URLconnection;

intresponseCode=httpConnection.getResponseCode();

System.out.println(responseCode);

if(responseCode==HttpURLConnection.HTTP_OK){//HTTP_OK为200

}else{

//oa提醒

addRemind(webSite);

//短信提醒

sendSm(webSite.getF5(),"网站'"+webSite.getF2()+"'出现异常,请检查网站服务!");

}

}catch(Exceptione){

//oa提醒

addRemind(webSite);

//短信提醒

sendSm(webSite.getF5(),"网站'"+webSite.getF2()+"'出现异常,请检查网站服务!");

}

}

相关推荐