代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
JAVA获取WEB服务器的名称
作者:
lovedreamland
/ 发布于
2014/7/17
/
532
JAVA获取服务器的名称,比如服务器是tomcat还是weblogic等等。在portal-kernel里面找到的。
package com.post.common.utils.other; public class ServerDetector { public static final String GERONIMO_ID = "geronimo"; public static final String GLASSFISH_ID = "glassfish"; public static final String JBOSS_ID = "jboss"; public static final String JETTY_ID = "jetty"; public static final String JONAS_ID = "jonas"; public static final String OC4J_ID = "oc4j"; public static final String RESIN_ID = "resin"; public static final String TOMCAT_ID = "tomcat"; public static final String WEBLOGIC_ID = "weblogic"; public static final String WEBSPHERE_ID = "websphere"; private static ServerDetector _instance = new ServerDetector(); private String _serverId; private Boolean _geronimo; private Boolean _glassfish; private Boolean _glassfish2; private Boolean _glassfish3; private Boolean _jBoss; private Boolean _jetty; private Boolean _jonas; private Boolean _oc4j; private Boolean _resin; private Boolean _tomcat; private Boolean _webLogic; private Boolean _webSphere; public static String getServerId() { ServerDetector sd = _instance; if (sd._serverId == null) { if (isGeronimo()) { sd._serverId = "geronimo"; } else if (isGlassfish()) { sd._serverId = "glassfish"; } else if (isJBoss()) { sd._serverId = "jboss"; } else if (isJOnAS()) { sd._serverId = "jonas"; } else if (isOC4J()) { sd._serverId = "oc4j"; } else if (isResin()) { sd._serverId = "resin"; } else if (isWebLogic()) { sd._serverId = "weblogic"; } else if (isWebSphere()) { sd._serverId = "websphere"; } if (isJetty()) { if (sd._serverId == null) { sd._serverId = "jetty"; } else { sd._serverId += "-jetty"; } } else if (isTomcat()) { if (sd._serverId == null) { sd._serverId = "tomcat"; } else { sd._serverId += "-tomcat"; } } if (sd._serverId == null) { throw new RuntimeException("Server is not supported"); } } return sd._serverId; } public static boolean isGeronimo() { ServerDetector sd = _instance; if (sd._geronimo == null) { sd._geronimo = _detect("/org/apache/geronimo/system/main/Daemon.class"); } return sd._geronimo.booleanValue(); } public static boolean isGlassfish() { ServerDetector sd = _instance; if (sd._glassfish == null) { String value = System.getProperty("com.sun.aas.instanceRoot"); if (value != null) { sd._glassfish = Boolean.TRUE; } else { sd._glassfish = Boolean.FALSE; } } return sd._glassfish.booleanValue(); } public static boolean isGlassfish2() { ServerDetector sd = _instance; if (sd._glassfish2 == null) { if ((isGlassfish()) && (!(isGlassfish3()))) { sd._glassfish2 = Boolean.TRUE; } else { sd._glassfish2 = Boolean.FALSE; } } return sd._glassfish2.booleanValue(); } public static boolean isGlassfish3() { ServerDetector sd = _instance; if (sd._glassfish3 == null) { String value = ""; if (isGlassfish()) { value = System.getProperty("product.name").trim(); } if (value.equals("GlassFish/v3")) { sd._glassfish3 = Boolean.TRUE; } else { sd._glassfish3 = Boolean.FALSE; } } return sd._glassfish3.booleanValue(); } public static boolean isJBoss() { ServerDetector sd = _instance; if (sd._jBoss == null) { sd._jBoss = _detect("/org/jboss/Main.class"); } return sd._jBoss.booleanValue(); } public static boolean isJetty() { ServerDetector sd = _instance; if (sd._jetty == null) { sd._jetty = _detect("/org/mortbay/jetty/Server.class"); } return sd._jetty.booleanValue(); } public static boolean isJOnAS() { ServerDetector sd = _instance; if (sd._jonas == null) { sd._jonas = _detect("/org/objectweb/jonas/server/Server.class"); } return sd._jonas.booleanValue(); } public static boolean isOC4J() { ServerDetector sd = _instance; if (sd._oc4j == null) { sd._oc4j = _detect("oracle.oc4j.util.ClassUtils"); } return sd._oc4j.booleanValue(); } public static boolean isResin() { ServerDetector sd = _instance; if (sd._resin == null) { sd._resin = _detect("/com/caucho/server/resin/Resin.class"); } return sd._resin.booleanValue(); } public static boolean isSupportsComet() { return false; } public static boolean isTomcat() { ServerDetector sd = _instance; if (sd._tomcat == null) { sd._tomcat = _detect("/org/apache/catalina/startup/Bootstrap.class"); } if (sd._tomcat == null) { sd._tomcat = _detect("/org/apache/catalina/startup/Embedded.class"); } return sd._tomcat.booleanValue(); } public static boolean isWebLogic() { ServerDetector sd = _instance; if (sd._webLogic == null) { sd._webLogic = _detect("/weblogic/Server.class"); } return sd._webLogic.booleanValue(); } public static boolean isWebSphere() { ServerDetector sd = _instance; if (sd._webSphere == null) { sd._webSphere = _detect("/com/ibm/websphere/product/VersionInfo.class"); } return sd._webSphere.booleanValue(); } private static Boolean _detect(String className) { try { ClassLoader.getSystemClassLoader().loadClass(className); return Boolean.TRUE; } catch (ClassNotFoundException cnfe) { ServerDetector sd = _instance; Class c = sd.getClass(); if (c.getResource(className) != null) { return Boolean.TRUE; } } return Boolean.FALSE; } }
试试其它关键字
WEB服务器
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
lovedreamland
贡献的其它代码
(
1
)
.
JAVA获取WEB服务器的名称
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3