Tomcat uses JMX to view the operation of the Web-app
JMX is already a standard component of J2SE in JDK 1.5.
In 1.4, JMX is defined by Sun specification and implemented by other companies.
Tomcat uses the JMX implemented by Sun Company.
Each version of Tomcat is different,
In Tomcat5, you can find a jmx.jar,4.1.x version in the bin directory, Server/lib/mx4j-jmx.jar
Here is an example
<% @page contenttype= "TEXT/PLAIN;CHARSET=GBK"%>
<% @page import= "Java.util.Iterator"%>
<% @page import= "Java.util.Set"%>
<% @page import= "Javax.management.MBeanServerFactory"%>
<% @page import= "Javax.management.MBeanServer"%>
<% @page import= "Javax.management.ObjectName"%>
<% @page import= "Javax.management.MBeanInfo"%>
<% @page import= "Javax.management.MBeanAttributeInfo"%>
<%
Out.clear ();
Mbeanserver mbeanserver = null;
if (Mbeanserverfactory.findmbeanserver (null). Size () > 0) {
Mbeanserver = (mbeanserver) mbeanserverfactory.findmbeanserver (null). Get (0);
}else{
Mbeanserver = Mbeanserverfactory.creatembeanserver ();
}
Set names = null;
try {
Names=mbeanserver.querynames (New ObjectName ("*:j2eetype=webmodule,*"), null);
Out.println ("Ok-number of results:" + names.size ());
Out.println ();
} catch (Exception e) {
Out.println ("Error-" + e.tostring ());
Return
}
Iterator It=names.iterator ();
while (It.hasnext ()) {
ObjectName oname= (ObjectName) it.next ();
Out.println ("Name:" + oname.tostring ());
try {
Mbeaninfo Minfo=mbeanserver.getmbeaninfo (oname);
Can ' t be null-i thinl
String Code=minfo.getclassname ();
if ("Org.apache.commons.modeler.BaseModelMBean". Equals (code)) {
Code= (String) Mbeanserver.getattribute (oname, "Modelertype");
}
Out.println ("Modelertype:" + code);
Mbeanattributeinfo attrs[]=minfo.getattributes ();
Object Value=null;
for (int i=0; i< attrs.length; i++) {
if (! attrs[i].isreadable ()) continue;
if (! issupported (Attrs[i].gettype ())) continue;
String Attname=attrs[i].getname ();
if (attname.indexof ("=") >=0 | |
Attname.indexof (":") >=0 | |
Attname.indexof ("") >=0)
{
Continue
}
try {
Value=mbeanserver.getattribute (Oname, AttName);
} catch (Throwable t) {
System.out.println ("Error getting attribute" + oname +
"+ AttName +" "+ t.tostring ());
Continue
}
if (value==null) continue;
if ("Modelertype". Equals (AttName)) continue;
String valuestring=value.tostring ();
Out.println (AttName + ":" + Escape (valuestring));
Out.println (AttName + ":" + valuestring);
}
} catch (Exception e) {
}
Out.println ();
}
%>