?? server_monitor.jsp
字號:
<%@ page contentType="text/plain; charset=UTF-8"%>
<%@ page language="java"%>
<%@ page import="org.apache.commons.httpclient.*,org.apache.commons.httpclient.methods.GetMethod"%>
<%
out.clear(); //清空當前的輸出內容(空格和換行符)
boolean serverOK = false; //檢查結果標識,默認為false
String url = request.getParameter("url"); //獲取URL地址
HttpClient client = new HttpClient(); //創建Http客戶端對象
GetMethod method = new GetMethod(url); //創建一個Get請求方法
try {
int statusCode = client.executeMethod(method); //執行Get請求方法,獲取結果狀態
//如果狀態為HttpStatus.SC_OK,即200,則設置檢查結果為true
if (statusCode == HttpStatus.SC_OK) {
serverOK = true;
}
} catch (Exception e) {
} finally {
method.releaseConnection(); //釋放Http連接
}
//根據serverOK標識輸出不同信息
if (serverOK) {
out.println("<span class='ok'>檢查正常</span>");
} else {
out.println("<span class='error'>出現異常</span>");
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -