导航:首页 > 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获取服务器类型相关的知识