If the Zamples security manager is configured to disable reflection then
the following program fragments will not work. The default setting for the security
manager does allow for reflection, so the following program fragments should
work on most installations.
File Access
List All Methods of a class
out.println("<h3>" + getClass().getName() + " Methods</h3>");
Method[] methods = getClass().getDeclaredMethods();
for (int i=0; i<methods.length; i++) {
Method m = methods[i];
Class retType = m.getReturnType();
Class[] paramTypes = m.getParameterTypes();
String name = m.getName();
out.print(Modifier.toString(m.getModifiers()));
out.print(" " + retType.getName() + " " + name + "(");
for (int j=0; j<paramTypes.length; j++) {
if (j>0) out.print(", ");
out.print(paramTypes[j].getName());
}
out.println(");");
}
Sample Output
Formatted for easier reading. Note that a JSP's class has a very long name!
sessions._0002fsessions_0002fl_00030x_00034syf_00031b_00031_0002ejspl0x4syf1b1_jsp_22
Methods public void _jspService(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse);
public final void _jspx_init();
Add New Code Samples Here
If you have code samples that don't fit into any of the topics above which you would like to contribute,
please put them here.
We'll sort them out into their own sections as appropriate later.
to add a new posting or reply to an existing posting.