導航:首頁 > IDC知識 > java獲取伺服器類型

java獲取伺服器類型

發布時間:2020-11-14 01:36:47

1、java程序中,如何實現獲取伺服器(我自己寫的一個普通的java程序做的伺服器)下的所有文件名然後傳遞給

就傳文件名的話可以直接傳ArrayList的對象流,把Socket 的outputstream封裝成ObjectOutputStream,然後就可以直接把整個ArrayList發出去了。

2、如何用JAVA得到遠程主機的操作系統類型

HTTP 伺服器,可以 通過查看瀏覽器遞交的 user-agent。。。。。。。但不保準的。。。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3、JAVA讀取伺服器二進制流byte類型 提取字元串

字元編碼的問題,推薦你看看張孝祥《java就業培訓》的IO一章中,有專門解釋字元編碼的章節,自己研究下,不然就算解決了這個問題,碰到其他的又不會了。

4、java代碼怎麼判斷當前伺服器是tomcat還是weblogic啊,就是獲取伺服器類型。。。。

package com.roger.query.util;  
import org.apache.log4j.Logger;  
/** 
 * @  伺服器類型探測 
 * @Date  2011/04/13 
 * **/  
public class ServerUtil {  
 public static final String GERONIMO_CLASS = "/org/apache/geronimo/system/main/Daemon.class";  
 public static final String JBOSS_CLASS = "/org/jboss/Main.class";  
 public static final String JETTY_CLASS = "/org/mortbay/jetty/Server.class";  
 public static final String JONAS_CLASS = "/org/objectweb/jonas/server/Server.class";  
 public static final String OC4J_CLASS = "/oracle/jsp/oc4jutil/Oc4jUtil.class";  
 public static final String ORION_CLASS = "/com/evermind/server/ApplicationServer.class";  
 public static final String PRAMATI_CLASS = "/com/pramati/Server.class";  
 public static final String RESIN_CLASS = "/com/caucho/server/resin/Resin.class";  
 public static final String REXIP_CLASS = "/com/tcc/Main.class";  
 public static final String SUN7_CLASS = "/com/iplanet/ias/tools/cli/IasAdminMain.class";  
 public static final String SUN8_CLASS = "/com/sun/enterprise/cli/framework/CLIMain.class";  
 public static final String TOMCAT_CLASS = "/org/apache/catalina/startup/Bootstrap.class";  
 public static final String WEBLOGIC_CLASS = "/weblogic/Server.class";  
 public static final String WEBSPHERE_CLASS = "/com/ibm/websphere/proct/VersionInfo.class";  
 public static String getServerId() {  
  ServerUtil sd = _instance;  
  if (sd._serverId == null) {  
   if (ServerUtil.isGeronimo()) {  
    sd._serverId = "geronimo";  
   } else if (ServerUtil.isJBoss()) {  
    sd._serverId = "jboss";  
   } else if (ServerUtil.isJOnAS()) {  
    sd._serverId = "jonas";  
   } else if (ServerUtil.isOC4J()) {  
    sd._serverId = "oc4j";  
   } else if (ServerUtil.isOrion()) {  
    sd._serverId = "orion";  
   } else if (ServerUtil.isResin()) {  
    sd._serverId = "resin";  
   } else if (ServerUtil.isWebLogic()) {  
    sd._serverId = "weblogic";  
   } else if (ServerUtil.isWebSphere()) {  
    sd._serverId = "websphere";  
   }  
   if (ServerUtil.isJetty()) {  
    if (sd._serverId == null) {  
     sd._serverId = "jetty";  
    } else {  
     sd._serverId += "-jetty";  
    }  
   } else if (ServerUtil.isTomcat()) {  
    if (sd._serverId == null) {  
     sd._serverId = "tomcat";  
    } else {  
     sd._serverId += "-tomcat";  
    }  
   }  
   if (_log.isInfoEnabled()) {  
    _log.info("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 = sd.getClass();  
   if (c.getResource(GERONIMO_CLASS) != null) {  
    sd._geronimo = Boolean.TRUE;  
   } else {  
    sd._geronimo = Boolean.FALSE;  
   }  
  }  
  return sd._geronimo.booleanValue();  
 }  
 public static boolean isJBoss() {  
  ServerUtil sd = _instance;  
  if (sd._jBoss == null) {  
   Class c = sd.getClass();  
   if (c.getResource(JBOSS_CLASS) != null) {  
    sd._jBoss = Boolean.TRUE;  
   } else {  
    sd._jBoss = Boolean.FALSE;  
   }  
  }  
  return sd._jBoss.booleanValue();  
 }  
 public static boolean isJetty() {  
  ServerUtil sd = _instance;  
  if (sd._jetty == null) {  
   Class c = sd.getClass();  
   if (c.getResource(JETTY_CLASS) != null) {  
    sd._jetty = Boolean.TRUE;  
   } else {  
    sd._jetty = Boolean.FALSE;  
   }  
  }  
  return sd._jetty.booleanValue();  
 }  
 public static boolean isJOnAS() {  
  ServerUtil sd = _instance;  
  if (sd._jonas == null) {  
   Class c = sd.getClass();  
   if (c.getResource(JONAS_CLASS) != null) {  
    sd._jonas = Boolean.TRUE;  
   } else {  
    sd._jonas = Boolean.FALSE;  
   }  
  }  
  return sd._jonas.booleanValue();  
 }  
 public static boolean isOC4J() {  
  ServerUtil sd = _instance;  
  if (sd._oc4j == null) {  
   Class c = sd.getClass();  
   if (c.getResource(OC4J_CLASS) != null) {  
    sd._oc4j = Boolean.TRUE;  
   } else {  
    sd._oc4j = Boolean.FALSE;  
   }  
  }  
  return sd._oc4j.booleanValue();  
 }  
 public static boolean isOrion() {  
  ServerUtil sd = _instance;  
  if (sd._orion == null) {  
   Class c = sd.getClass();  
   if (c.getResource(ORION_CLASS) != null) {  
    sd._orion = Boolean.TRUE;  
   } else {  
    sd._orion = Boolean.FALSE;  
   }  
  }  
  return sd._orion.booleanValue();  
 }  
 public static boolean isPramati() {  
  ServerUtil sd = _instance;  
  if (sd._pramati == null) {  
   Class c = sd.getClass();  
   if (c.getResource(PRAMATI_CLASS) != null) {  
    sd._pramati = Boolean.TRUE;  
   } else {  
    sd._pramati = Boolean.FALSE;  
   }  
  }  
  return sd._pramati.booleanValue();  
 }  
 public static boolean isResin() {  
  ServerUtil sd = _instance;  
  if (sd._resin == null) {  
   Class c = sd.getClass();  
   if (c.getResource(RESIN_CLASS) != null) {  
    sd._resin = Boolean.TRUE;  
   } else {  
    sd._resin = Boolean.FALSE;  
   }  
  }  
  return sd._resin.booleanValue();  
 }  
 public static boolean isRexIP() {  
  ServerUtil sd = _instance;  
  if (sd._rexIP == null) {  
   Class c = sd.getClass();  
   if (c.getResource(REXIP_CLASS) != null) {  
    sd._rexIP = Boolean.TRUE;  
   } else {  
    sd._rexIP = Boolean.FALSE;  
   }  
  }  
  return sd._rexIP.booleanValue();  
 }  
 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 = sd.getClass();  
   if (c.getResource(SUN7_CLASS) != null) {  
    sd._sun7 = Boolean.TRUE;  
   } else {  
    sd._sun7 = Boolean.FALSE;  
   }  
  }  
  return sd._sun7.booleanValue();  
 }  
 public static boolean isSun8() {  
  ServerUtil sd = _instance;  
  if (sd._sun8 == null) {  
   Class c = sd.getClass();  
   if (c.getResource(SUN8_CLASS) != null) {  
    sd._sun8 = Boolean.TRUE;  
   } else {  
    sd._sun8 = Boolean.FALSE;  
   }  
  }  
  return sd._sun8.booleanValue();  
 }  
 public static boolean isTomcat() {  
  ServerUtil sd = _instance;  
  if (sd._tomcat == null) {  
   Class c = sd.getClass();  
   if (c.getResource(TOMCAT_CLASS) != null) {  
    sd._tomcat = Boolean.TRUE;  
   } else {  
    sd._tomcat = Boolean.FALSE;  
   }  
  }  
  return sd._tomcat.booleanValue();  
 }  
 public static boolean isWebLogic() {  
  ServerUtil sd = _instance;  
  if (sd._webLogic == null) {  
   Class c = sd.getClass();  
   if (c.getResource(WEBLOGIC_CLASS) != null) {  
    sd._webLogic = Boolean.TRUE;  
   } else {  
    sd._webLogic = Boolean.FALSE;  
   }  
  }  
  return sd._webLogic.booleanValue();  
 }  
 public static boolean isWebSphere() {  
  ServerUtil sd = _instance;  
  if (sd._webSphere == null) {  
   Class c = sd.getClass();  
   if (c.getResource(WEBSPHERE_CLASS) != null) {  
    sd._webSphere = Boolean.TRUE;  
   } else {  
    sd._webSphere = Boolean.FALSE;  
   }  
  }  
  return sd._webSphere.booleanValue();  
 }  
 private ServerUtil() {  
 }  
 private static Logger _log = Logger.getLogger(ServerUtil.class);  
 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 的博客,求採納

5、java獲取伺服器文件,怎樣用url返回

下面提供二種方法會使用java發送url請求,並獲取伺服器返回的值

第一種方法:
代碼如下:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.util.EntityUtils;

(StringurlStr,Stringparam1,Stringparam2)throwsException{
StringtempStr=null;
HttpClienthttpclient=newDefaultHttpClient();
Propertiesproperties=newProperties();
HttpEntityentity=null;
StringxmlContent="";
try
{

//設置超時時間
httpclient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,20000);
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,20000);

//封裝需要傳遞的參數
List<NameValuePair>nvps=newArrayList<NameValuePair>();
nvps.add(newBasicNameValuePair("mainMemoCode",strmainMemoCode));
nvps.add(newBasicNameValuePair("recordPassWord",strrecordPassWord));
//客戶端的請求方法類型
HttpPosthttpPost=newHttpPost(urlStr);
httpPost.setEntity(newUrlEncodedFormEntity(nvps,"GBK"));
HttpResponseresponse=httpclient.execute(httpPost);

//獲取伺服器返回Http的Content-Type的值
tempStr=response.getHeaders("Content-Type")[0].getValue().toString();

//獲取伺服器返回頁面的值
entity=response.getEntity();
xmlContent=EntityUtils.toString(entity);
Stringstrmessage=null;
System.out.println(xmlContent);
System.out.println(response.getHeaders("Content-Type")[0].getValue().toString());
httpPost.abort();

}
catch(SocketTimeoutExceptione)
{
}
catch(Exceptionex)
{
ex.printStackTrace();
}
finally{
httpclient.getConnectionManager().shutdown();
}
第二種方法:

代碼如下:


(StringurlStr,Stringparam1,Stringparam2)throwsException{

HttpURLConnectionurl_con=null;
try{
URLurl=newURL(urlStr);
StringBufferbankXmlBuffer=newStringBuffer();
//創建URL連接,提交到數據,獲取返回結果
HttpURLConnectionconnection=(HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent","directclient");

PrintWriterout=newPrintWriter(newOutputStreamWriter(connection.getOutputStream(),"GBK"));
out.println(param);
out.close();
BufferedReaderin=newBufferedReader(newInputStreamReader(connection
.getInputStream(),"GBK"));

StringinputLine;

while((inputLine=in.readLine())!=null){
bankXmlBuffer.append(inputLine);
}
in.close();
tempStr=bankXmlBuffer.toString();
}
catch(Exceptione)
{
System.out.println("發送GET請求出現異常!"+e);
e.printStackTrace();

}finally{
if(url_con!=null)
url_con.disconnect();
}

returntmpeStr;
}

總結:多練習代碼,熟練之後才能更快速的去了解代碼的學習的方法。多去獲取一些思維方面的書籍可以看看。

6、java 如何在運行期判斷伺服器類型

request.getServerName();
request.getServerPort();

7、java獲得當前伺服器的操作系統是什麼?怎麼獲得

import java.util.Properties;

public class Test{

public static void main (String args[]){
Properties props=System.getProperties(); //系統屬性

System.out.println("Java的運行環境版本:"+props.getProperty("java.version"));
System.out.println("Java的運行環境供應商:"+props.getProperty("java.vendor"));
System.out.println("Java供應商的URL:"+props.getProperty("java.vendor.url"));
System.out.println("Java的安裝路徑:"+props.getProperty("java.home"));
System.out.println("Java的虛擬機規范版本:"+props.getProperty("java.vm.specification.version"));
System.out.println("Java的虛擬機規范供應商:"+props.getProperty("java.vm.specification.vendor"));
System.out.println("Java的虛擬機規范名稱:"+props.getProperty("java.vm.specification.name"));
System.out.println("Java的虛擬機實現版本:"+props.getProperty("java.vm.version"));
System.out.println("Java的虛擬機實現供應商:"+props.getProperty("java.vm.vendor"));
System.out.println("Java的虛擬機實現名稱:"+props.getProperty("java.vm.name"));
System.out.println("Java運行時環境規范版本:"+props.getProperty("java.specification.version"));
System.out.println("Java運行時環境規范供應商:"+props.getProperty("java.specification.vender"));
System.out.println("Java運行時環境規范名稱:"+props.getProperty("java.specification.name"));
System.out.println("Java的類格式版本號:"+props.getProperty("java.class.version"));
System.out.println("Java的類路徑:"+props.getProperty("java.class.path"));
System.out.println("載入庫時搜索的路徑列表:"+props.getProperty("java.library.path"));
System.out.println("默認的臨時文件路徑:"+props.getProperty("java.io.tmpdir"));
System.out.println("一個或多個擴展目錄的路徑:"+props.getProperty("java.ext.dirs"));
System.out.println("操作系統的名稱:"+props.getProperty("os.name"));
System.out.println("操作系統的構架:"+props.getProperty("os.arch"));
System.out.println("操作系統的版本:"+props.getProperty("os.version"));
System.out.println("文件分隔符:"+props.getProperty("file.separator")); //在 unix 系統中是」/」
System.out.println("路徑分隔符:"+props.getProperty("path.separator")); //在 unix 系統中是」:」
System.out.println("行分隔符:"+props.getProperty("line.separator")); //在 unix 系統中是」/n」
System.out.println("用戶的賬戶名稱:"+props.getProperty("user.name"));
System.out.println("用戶的主目錄:"+props.getProperty("user.home"));
System.out.println("用戶的當前工作目錄:"+props.getProperty("user.dir"));

}

}

8、關於java獲取伺服器問題

首先復要確定你的這個東東是什制么架構的
B/S 瀏覽器伺服器模式
C/S 客戶端伺服器模式
B/S的話,客戶端看用什麼,Applet還是Flash,通過Socket還有JSP頁面裡面通過Java代碼可以獲取到伺服器的IP地址
C/S的話,就必須要明確伺服器所在地址了

9、java應用伺服器的java應用伺服器分類

在J2EE應用伺服器領域,Jboss是發展最為迅速的應用伺服器。由於Jboss遵循商業友好的LGPL授權分發,並且由開源社區開發,這使得Jboss廣為流行。另外,Jboss應用伺服器還具有許多優秀的特質。
其一,它將具有革命性的JMX微內核服務作為其匯流排結構;
其二,它本身就是面向服務的架構(Service-Oriented Architecture,SOA);
其三,它還具有統一的類裝載器,從而能夠實現應用的熱部署和熱卸載能力。因此,它是高度模塊化的和松耦合的。Jboss用戶的積極反饋告訴我們,Jboss應用伺服器是健壯的、高質量的,而且還具有良好的性能。  為滿足企業級市場日益增長的需求,Jboss公司從2003年開始就推出了24*7、專業級產品支持服務。同時,為拓展Jboss的企業級市場,Jboss公司還簽訂了許多渠道合作夥伴。比如,Jboss公司同HP、Novell、Computer Associates、Unisys等都是合作夥伴。
在2004年6月,Jboss公司宣布,Jboss應用伺服器通過了Sun公司的J2EE認證。這是Jboss應用伺服器發展史上至今為止最重要的里程碑。與此同時,Jboss一直在緊跟最新的J2EE規范,而且在某些技術領域引領J2EE規范的開發。因此,無論在商業領域,還是在開源社區,Jboss成為了第一個通過J2EE 1.4認證的主流應用伺服器。現在,Jboss應用伺服器已經真正發展成具有企業強度(即,支持關鍵級任務的應用)的應用伺服器。  Jboss 4.0作為J2EE認證的重要成果之一,已經於2004年9月順利發布了。同時,Jboss 4.0還提供了Jboss AOP(Aspect-Oriented Programming,面向方面編程)組件。近來,AOP吸引了大量開發者的關注。它提供的新的編程模式使得用戶能夠將方面(比如,事務)從底層業務邏輯中分離出來,從而能夠縮短軟體開發周期。用戶能夠單獨使用Jboss AOP,即能夠在Jboss應用伺服器外部使用它。或者,用戶也可以在應用伺服器環境中使用它。Jboss AOP 1.0已經在2004年10月發布了。 JFox 是 Open Source Java EE Application Server,致力於提供輕量級的Java EE應用伺服器,從3.0開始,JFox提供了一個支持模塊化的MVC框架,以簡化EJB以及Web應用的開發! 如果您正在尋找一個簡單、輕量、高效、完善的Java EE開發平台,那麼JFox正是您需要的。
JFox 3.0 擁有以下特性:
重新設計的 IoC 微內核,融入 OSGi 模塊化思想 設計成嵌入式架構,能夠和任何 Java Web Server集成部署 支持 EJB3,JPA規范,支持容器內和容器外兩種方式運行EJB和JPA組件 支持 EJB 發布成Web Service 採用 JOTM提供事務處理,支持兩階段提交(2PC) 採用 XAPool提供 XA DataSource,支持智能連接池管理 內置 MVC 框架,實現自動Form Mapping,Validator,Uploading等功能,支持JSP/Velocity/Freemarker頁面引擎,並支持直接在Action中注入EJB 支持多應用模塊部署,讓中大型應用充分享受模塊化開發帶來的優勢 提供 Manager 管理模塊,可以查看和管理各種運行時參數 提供根據 JFox 特色重寫的 Petstore 應用模塊。 Apache Geronimo 是 Apache 軟體基金會的開放源碼J2EE伺服器,它集成了眾多先進技術和設計理念。 這些技術和理念大多源自獨立的項目,配置和部署模型也各不相同。 Geronimo能將這些項目和方法的配置及部署完全整合到一個統一、易用的模型中。
作為符合J2EE標準的伺服器,Geronimo提供了豐富的功能集和無責任 Apache 許可,具備「立即部署」式J2EE 1.4容器的各種優點,其中包括:
· 符合J2EE1.4標準的伺服器
· 預集成的開放源碼項目
· 統一的集成模型
· 可伸縮性、可管理性和配置管理功能 ObjectWeb組織啟動一個新的項目:EasyBeans一個輕量級的EJB3容器,雖然還沒有正式發布,但是已經可以從它們的subversion倉庫中檢出代碼。

與java獲取伺服器類型相關的知識