标签:
网上摘抄:
参考代码如下:
[java] view plaincopyprint?
/**
* 根据协议和scheme获取服务端口号
* @return 端口号
*/
private static String getHttpPort(String protocol, String scheme)
{
MBeanServer mBeanServer = null;
if (MBeanServerFactory.findMBeanServer(null).size() > 0)
{
mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
}
Set names = null;
try
{
names = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null);
}
catch (Exception e)
{
return "";
}
Iterator it = names.iterator();
ObjectName oname = null;
while (it.hasNext())
{
oname = (ObjectName)it.next();
String pvalue = (String)mBeanServer.getAttribute(oname, "protocol");
String svalue = (String)mBeanServer.getAttribute(oname, "scheme");
if (protocol.equals(pvalue) && scheme.equals(svalue))
{
return ((Integer)mBeanServer.getAttribute(oname, "port")).toString();
}
}
}
return "";
}
标签:
原文地址:http://www.cnblogs.com/recordmytime/p/4939467.html