Tomcat:

public static String getServerPort(boolean secure) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
MBeanServer mBeanServer = null;
if (MBeanServerFactory.findMBeanServer(null).size() > ) {
mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get();
} if (mBeanServer == null) {
System.out.println("调用findMBeanServer查询到的结果为null");
return "";
} Set<ObjectName> names = null;
try {
names = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null);
} catch (Exception e) {
return "";
}
Iterator<ObjectName> it = names.iterator();
ObjectName oname = null;
while (it.hasNext()) {
oname = (ObjectName)it.next();
String protocol = (String)mBeanServer.getAttribute(oname, "protocol");
String scheme = (String)mBeanServer.getAttribute(oname, "scheme");
Boolean secureValue = (Boolean)mBeanServer.getAttribute(oname, "secure");
Boolean SSLEnabled = (Boolean)mBeanServer.getAttribute(oname, "SSLEnabled");
if (SSLEnabled != null && SSLEnabled) {// tomcat6开始用SSLEnabled
secureValue = true;// SSLEnabled=true但secure未配置的情况
scheme = "https";
}
if (protocol != null && ("HTTP/1.1".equals(protocol) || protocol.contains("http"))) {
if (secure && "https".equals(scheme) && secureValue) {
return ((Integer)mBeanServer.getAttribute(oname, "port")).toString();
} else if (!secure && !"https".equals(scheme) && !secureValue) {
return ((Integer)mBeanServer.getAttribute(oname, "port")).toString();
}
}
}
return "";
}

Weblogic参考:

http://blog.csdn.net/yunzhu666/article/details/8662039

获取 web 服务器 port的更多相关文章

  1. Java获取Web服务器文件

    Java获取Web服务器文件 如果获取的是服务器上某个目录下的有关文件,就相对比较容易,可以设定死绝对目录,但是如果不能设定死绝对目录,也不确定web服务器的安装目录,可以考虑如下两种方式: 方法一: ...

  2. 浏览器获取WEB服务器时间

    /* * 获取XMLHttpRequest对象 */ function CreateXMLHttpRequest() { var xmlreq = false; if (window.ActiveXO ...

  3. 获取web服务器路径的方法 getResourceAsStream

    1.先获取 serlvetContext对象 2.调用getResourceAsStream  在方法里 "\"表示当前web的根目录  还要拼接上具体的文件路径 ServletC ...

  4. 04-HTTP协议和静态Web服务器

    一.HTTP协议(HyperText Transfer Protocol)     超文本传输协议,超文本是超级文本的缩写,是指超越文本限制或者超链接,比如:图片.音乐.视频.超链接等等都属于超文本. ...

  5. 转:浏览器与WEB服务器工作过程举例

    用户通过“浏览器”访问因特网上的WEB服务器,浏览器和服务器之间的信息交换使用超文本传输协议(HTTP--HyperText Transfer Protocol). 例:用户访问东南大学主页 Http ...

  6. msf客户端渗透(九):获取PHP服务器shell

    如果一个网页存在可以include外链的漏洞,我们可以利用这个漏洞include本机上的文件,从而获取web服务器的shell. 设置目标的IP 根据网页的路径设置参数 设置cookie 选择payl ...

  7. ASP.NET获取web应用程序的路径

    服务器磁盘上的物理路径: HttPRuntime.AppDomainAppPath虚拟程序路径: HttpRuntime.AppDomainAppVirtualPath 任何于Request/Http ...

  8. web服务器获取请求客户端真实地址的方法

    服务器获取客户端或者网页的请求,获取IP时需要注意,因为一个请求到达服务器之前,一般都会经过一层或者多层代理服务器,比如反向代理服务器将http://192.168.1.10:port/ 的URL反向 ...

  9. 如何快速建立一个测试资源Web服务器及异步获取资源(Unity3D)

    背景 1.最近看了几位专栏作家的文章,几篇提到了资源通过网络的动态获取.如何建立一个快速的测试环境,不免是一个问题,也就最简单的就是假设http服务器了,微软系的当然首选的IIS了,别的也能用阿帕奇或 ...

随机推荐

  1. SQL查询优化:详解SQL Server非聚集索引(转载)

    本文是转载,原文地址 http://tech.it168.com/a2011/1228/1295/000001295176.shtml 在SQL SERVER中,非聚集索引其实可以看作是一个含有聚集索 ...

  2. (4.28)for xml path 在合并拆分上的作用演示

    for xml path 用于合并与拆分 1.合并 很多时候需要在SQL Server中创建逗号分隔列表.这可以使用SQL Server的DOR XML PATH功能完成.与select语句一起使用时 ...

  3. 6个laravel常用目录路径函数

    public_path() public_path函数返回public目录的绝对路径:$path = public_path(); base_path() base_path函数返回项目根目录的绝对路 ...

  4. MYSQL的价格

    MYSQL的价格 来自:http://www.greatlinux.com/column/column.do?nodeid=2c90c6093416705c013416f283f40004&c ...

  5. vue中less的使用

    1.安装:npm install less less-loader --save 2.修改webpack.config.js文件,配置loader加载依赖,让其支持外部的less,在原来的代码上添加 ...

  6. [硬件]Urg_viewer数据读取

    首先,数据读取部分开启了两个后台线程,一个负责串口的连接和测试:一个负责数据的接收. 几个基本概念: 建立连接和关闭连接. 开始记录和停止记录. 保存CSV文件. 1.查找COM端口,Urg_driv ...

  7. [py]__name__ 属于哪个文件

    name: 属于哪个文件 文件的 main 类的 class Person(object): """ 定义一个类 """ count = 1 ...

  8. 读取Request body方法

    一:传统方法 StringBuilder stringBuilder = new StringBuilder(); BufferedReader bufferedReader = null; try ...

  9. HTML5服务器消息推送(java版)

    前端代码(html5.html): <html> <meta http-equiv="Content-Type" content="text/html; ...

  10. 重签名提示:无法对 jar 进行签名: java.util.zip.ZipException

    使用jarsigner对APK重签名,提示:jarsigner: 无法对 jar 进行签名: java.util.zip.ZipException: invalid entry compressed ...