posted 22 years ago
Hi Barry,
I had the same problem and I have figured it out. Here is the example I did and it works now. Hope this helps.
Trish
---------------------------------------------------------------
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
import java.io.*;
import java.lang.reflect.Method;
public class test1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
performTask(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
performTask(request,response);
}
public void performTask(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out = null;
response.setContentType(CONTENT_TYPE);
out = response.getWriter();
out.println("test");
String a = "help";
try {
Class classObj = Class.forName("test1");
Class[] params = new Class[3];
params[0] = Integer.TYPE;
params[1] = a.getClass();
params[2] = out.getClass();
Method method = classObj.getMethod("testMethod",params);
test1 obj2 = new test1();
Object[] args = new Object[3];
args[0] = new Integer(10);
args[1] = a;
args[2] = out;
Object retObj = method.invoke(obj2,args);
} catch (Exception e) {
out.println(e);
}
out.println("performTask:here ");
}
public void testMethod(int i, String a, PrintWriter out) {
out.println(a);
out.println(i);
}
}