java - How to display output in servlet when invoking a method dynamically -


I am trying to load a class dynamically and calling it one of its own method from Servlet I am

In my service I have the following code:

  PrintWriter out = response.getWriter (); {Class & lt;? & Gt; Obj = Class.forName (myclassName); Method method = obj.getClass (). GetMethod (myMethodName); String Return Value = (string) method.invoke (obj, null); Out.println (returnValue); } Hold (exception E) {}   

and in my class:

  public class student class {public string index () {return "it is From the student class "; }}   

The problem is that when I run my application it does not show anything it is from the student class to get the output as Hopefully, that's basically returning the class of the index method.

Can you please tell me how to solve this problem?

Your incoming usage is incorrect:

 < Code> class & lt ;? & Gt; Obj = Class.forName (myclassName); // It returns a class, not an example method method = obj.getClass (). GetMethod (myMethodName); String Return Value = (string) method.invoke (obj, null);   

Fair use will be something like this:

  class   

.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -