Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>UserController.class.getDeclaredMethod(string, args) returns the method if it is declared in the class UserController. </p> <p>You can make all your servlet classes inherit by a parent servlet, as Funtik suggested and then add this method in the superclass: </p> <pre><code>protected Method methodToInvoke(String action) { Class[] args = { HttpServletRequest.class, HttpServletResponse.class }; Method method = this.getClass().getDeclaredMethod(action, args); } </code></pre> <p>This method searches to find a method of the class of servlet that is being executed (this.getClass()). You can also include the execution method in the supertype sevlet class.</p> <p>Alternatively, if you don't want or just can't subclass all your servlets, you can put this functionality in a utility class, but then you should pass the servlet class as a parameter.</p> <pre><code>protected static Method methodToInvoke(String action, Class clazz) { Class[] args = { HttpServletRequest.class, HttpServletResponse.class }; Method method = clazz.getDeclaredMethod(action, args); } </code></pre> <p>But then you should pass this.getClass() as an argument when you call this static method from a servlet.</p> <p>You can also take a look at <a href="http://code.google.com/p/bo2/source/browse/trunk/Bo2Utils/main/gr/interamerican/bo2/utils/ReflectionUtils.java" rel="nofollow">http://code.google.com/p/bo2/source/browse/trunk/Bo2Utils/main/gr/interamerican/bo2/utils/ReflectionUtils.java</a>. It contains some of the utilities that you need (find a method, execute it etc)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload