怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数

怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数,第1张

1jdbcproperties

driver=commicrosoftjdbcsqlserverSQLServerDriver

url=jdbc:microsoft:sqlserver://Ip地址:1433;databaseName=test

user=test

password=test

2一个Servlet

import javaioPrintStream;

import javasql;

import javautilResourceBundle;

public class DBOperator

{

public DBOperator()

{

}

public static void main(String args[])

{

Connection con = getConnection();

Systemoutprintln("connection success");

closeConnection(con);

Systemoutprintln("close success");

}

public static Connection getConnection()

{

try

{

return DriverManagergetConnection(url, user,

password);

}

catch(SQLException e)

{

eprintStackTrace();

}

return null;

}

public static void closeConnection(Connection con)

{

try

{

if(con != null)

conclose();

}

catch(SQLException e)

{

eprintStackTrace();

}

}

private static String url;

private static String user;

private static String password;

static

{

ResourceBundle bundle = ResourceBundlegetBundle("路径");

try

{

ClassforName(bundlegetString("driver"));

}

catch(ClassNotFoundException e)

{

eprintStackTrace();

}

url = bundlegetString("url");

user = bundlegetString("user");

password = bundlegetString("password");

}

}

package comrogerqueryutil;  

import orgapachelog4jLogger;  

  @  服务器类型探测 

  @Date  2011/04/13 

  /  

public class ServerUtil {  

 public static final String GERONIMO_CLASS = "/org/apache/geronimo/system/main/Daemonclass";  

 public static final String JBOSS_CLASS = "/org/jboss/Mainclass";  

 public static final String JETTY_CLASS = "/org/mortbay/jetty/Serverclass";  

 public static final String JONAS_CLASS = "/org/objectweb/jonas/server/Serverclass";  

 public static final String OC4J_CLASS = "/oracle/jsp/oc4jutil/Oc4jUtilclass";  

 public static final String ORION_CLASS = "/com/evermind/server/ApplicationServerclass";  

 public static final String PRAMATI_CLASS = "/com/pramati/Serverclass";  

 public static final String RESIN_CLASS = "/com/caucho/server/resin/Resinclass";  

 public static final String REXIP_CLASS = "/com/tcc/Mainclass";  

 public static final String SUN7_CLASS = "/com/iplanet/ias/tools/cli/IasAdminMainclass";  

 public static final String SUN8_CLASS = "/com/sun/enterprise/cli/framework/CLIMainclass";  

 public static final String TOMCAT_CLASS = "/org/apache/catalina/startup/Bootstrapclass";  

 public static final String WEBLOGIC_CLASS = "/weblogic/Serverclass";  

 public static final String WEBSPHERE_CLASS = "/com/ibm/websphere/product/VersionInfoclass";  

 public static String getServerId() {  

  ServerUtil sd = _instance;  

  if (sd_serverId == null) {  

   if (ServerUtilisGeronimo()) {  

    sd_serverId = "geronimo";  

   } else if (ServerUtilisJBoss()) {  

    sd_serverId = "jboss";  

   } else if (ServerUtilisJOnAS()) {  

    sd_serverId = "jonas";  

   } else if (ServerUtilisOC4J()) {  

    sd_serverId = "oc4j";  

   } else if (ServerUtilisOrion()) {  

    sd_serverId = "orion";  

   } else if (ServerUtilisResin()) {  

    sd_serverId = "resin";  

   } else if (ServerUtilisWebLogic()) {  

    sd_serverId = "weblogic";  

   } else if (ServerUtilisWebSphere()) {  

    sd_serverId = "websphere";  

   }  

   if (ServerUtilisJetty()) {  

    if (sd_serverId == null) {  

     sd_serverId = "jetty";  

    } else {  

     sd_serverId += "-jetty";  

    }  

   } else if (ServerUtilisTomcat()) {  

    if (sd_serverId == null) {  

     sd_serverId = "tomcat";  

    } else {  

     sd_serverId += "-tomcat";  

    }  

   }  

   if (_logisInfoEnabled()) {  

    _loginfo("Detected server " + sd_serverId);  

   }  

   if (sd_serverId == null) {  

    throw new RuntimeException("Server is not supported");  

   }  

  }  

  return sd_serverId;  

 }  

 public static boolean isGeronimo() {  

  ServerUtil sd = _instance;  

  if (sd_geronimo == null) {  

   Class c = sdgetClass();  

   if (cgetResource(GERONIMO_CLASS) != null) {  

    sd_geronimo = BooleanTRUE;  

   } else {  

    sd_geronimo = BooleanFALSE;  

   }  

  }  

  return sd_geronimobooleanValue();  

 }  

 public static boolean isJBoss() {  

  ServerUtil sd = _instance;  

  if (sd_jBoss == null) {  

   Class c = sdgetClass();  

   if (cgetResource(JBOSS_CLASS) != null) {  

    sd_jBoss = BooleanTRUE;  

   } else {  

    sd_jBoss = BooleanFALSE;  

   }  

  }  

  return sd_jBossbooleanValue();  

 }  

 public static boolean isJetty() {  

  ServerUtil sd = _instance;  

  if (sd_jetty == null) {  

   Class c = sdgetClass();  

   if (cgetResource(JETTY_CLASS) != null) {  

    sd_jetty = BooleanTRUE;  

   } else {  

    sd_jetty = BooleanFALSE;  

   }  

  }  

  return sd_jettybooleanValue();  

 }  

 public static boolean isJOnAS() {  

  ServerUtil sd = _instance;  

  if (sd_jonas == null) {  

   Class c = sdgetClass();  

   if (cgetResource(JONAS_CLASS) != null) {  

    sd_jonas = BooleanTRUE;  

   } else {  

    sd_jonas = BooleanFALSE;  

   }  

  }  

  return sd_jonasbooleanValue();  

 }  

 public static boolean isOC4J() {  

  ServerUtil sd = _instance;  

  if (sd_oc4j == null) {  

   Class c = sdgetClass();  

   if (cgetResource(OC4J_CLASS) != null) {  

    sd_oc4j = BooleanTRUE;  

   } else {  

    sd_oc4j = BooleanFALSE;  

   }  

  }  

  return sd_oc4jbooleanValue();  

 }  

 public static boolean isOrion() {  

  ServerUtil sd = _instance;  

  if (sd_orion == null) {  

   Class c = sdgetClass();  

   if (cgetResource(ORION_CLASS) != null) {  

    sd_orion = BooleanTRUE;  

   } else {  

    sd_orion = BooleanFALSE;  

   }  

  }  

  return sd_orionbooleanValue();  

 }  

 public static boolean isPramati() {  

  ServerUtil sd = _instance;  

  if (sd_pramati == null) {  

   Class c = sdgetClass();  

   if (cgetResource(PRAMATI_CLASS) != null) {  

    sd_pramati = BooleanTRUE;  

   } else {  

    sd_pramati = BooleanFALSE;  

   }  

  }  

  return sd_pramatibooleanValue();  

 }  

 public static boolean isResin() {  

  ServerUtil sd = _instance;  

  if (sd_resin == null) {  

   Class c = sdgetClass();  

   if (cgetResource(RESIN_CLASS) != null) {  

    sd_resin = BooleanTRUE;  

   } else {  

    sd_resin = BooleanFALSE;  

   }  

  }  

  return sd_resinbooleanValue();  

 }  

 public static boolean isRexIP() {  

  ServerUtil sd = _instance;  

  if (sd_rexIP == null) {  

   Class c = sdgetClass();  

   if (cgetResource(REXIP_CLASS) != null) {  

    sd_rexIP = BooleanTRUE;  

   } else {  

    sd_rexIP = BooleanFALSE;  

   }  

  }  

  return sd_rexIPbooleanValue();  

 }  

 public static boolean isSun() {  

  if (isSun7() || isSun8()) {  

   return true;  

  } else {  

   return false;  

  }  

 }  

 public static boolean isSun7() {  

  ServerUtil sd = _instance;  

  if (sd_sun7 == null) {  

   Class c = sdgetClass();  

   if (cgetResource(SUN7_CLASS) != null) {  

    sd_sun7 = BooleanTRUE;  

   } else {  

    sd_sun7 = BooleanFALSE;  

   }  

  }  

  return sd_sun7booleanValue();  

 }  

 public static boolean isSun8() {  

  ServerUtil sd = _instance;  

  if (sd_sun8 == null) {  

   Class c = sdgetClass();  

   if (cgetResource(SUN8_CLASS) != null) {  

    sd_sun8 = BooleanTRUE;  

   } else {  

    sd_sun8 = BooleanFALSE;  

   }  

  }  

  return sd_sun8booleanValue();  

 }  

 public static boolean isTomcat() {  

  ServerUtil sd = _instance;  

  if (sd_tomcat == null) {  

   Class c = sdgetClass();  

   if (cgetResource(TOMCAT_CLASS) != null) {  

    sd_tomcat = BooleanTRUE;  

   } else {  

    sd_tomcat = BooleanFALSE;  

   }  

  }  

  return sd_tomcatbooleanValue();  

 }  

 public static boolean isWebLogic() {  

  ServerUtil sd = _instance;  

  if (sd_webLogic == null) {  

   Class c = sdgetClass();  

   if (cgetResource(WEBLOGIC_CLASS) != null) {  

    sd_webLogic = BooleanTRUE;  

   } else {  

    sd_webLogic = BooleanFALSE;  

   }  

  }  

  return sd_webLogicbooleanValue();  

 }  

 public static boolean isWebSphere() {  

  ServerUtil sd = _instance;  

  if (sd_webSphere == null) {  

   Class c = sdgetClass();  

   if (cgetResource(WEBSPHERE_CLASS) != null) {  

    sd_webSphere = BooleanTRUE;  

   } else {  

    sd_webSphere = BooleanFALSE;  

   }  

  }  

  return sd_webSpherebooleanValue();  

 }  

 private ServerUtil() {  

 }  

 private static Logger _log = LoggergetLogger(ServerUtilclass);  

 private static ServerUtil _instance = new ServerUtil();  

 private String _serverId;  

 private Boolean _geronimo;  

 private Boolean _jBoss;  

 private Boolean _jetty;  

 private Boolean _jonas;  

 private Boolean _oc4j;  

 private Boolean _orion;  

 private Boolean _pramati;  

 private Boolean _resin;  

 private Boolean _rexIP;  

 private Boolean _sun7;  

 private Boolean _sun8;  

 private Boolean _tomcat;  

 private Boolean _webLogic;  

 private Boolean _webSphere;     

   

}

代码来自 javaRoger 的博客,求采纳

以上就是关于怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数全部的内容,包括:怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数、nginx做反向代理负载均衡 Java怎么获取后端服务器获取用户IP、如何用Java实现Web服务器等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9594092.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存