- <%@ page import="javax.naming.Context,
- javax.naming.InitialContext,
- weblogic.management.MBeanHome,
- weblogic.management.configuration.ServerMBean"
- %>
- <%!
- String serverName, serverAddress;
- int serverPort;
- private void getServerInfo() throws Exception {
- Context myCtx = new InitialContext();
- MBeanHome home = (MBeanHome)myCtx.lookup(MBeanHome.LOCAL_JNDI_NAME);
- serverName=home.getMBeanServer().getServerName();
- ServerMBean sc = (ServerMBean)home.getConfigurationMBean(serverName, "ServerConfig");
- serverAddress = sc.getListenAddress();
- serverPort = sc.getListenPort();
- }
- %>
- <%
- try {
- getServerInfo();
- } catch (Exception e) {
- }
- %>
- Server Name: <%=serverName %>
- Server Address: <%=serverAddress %>
- Server Port: <%=serverPort %>
将上述代码保存成jsp文件,放置到web app目录中,即可访问其得到服务器名字、IP地址和端口号。如果是匿名用户(尚未登陆)则会出现安全错误,因为WebLogic Server缺省情况下不允许匿名用户访问MBean信息,可在控制台中更改,如下图: