invoking methods from another servlet


Web tier: servlets, JSP, Web frameworks: invoking methods from another servlet

  1. invoking methods from another servlet (3 messages)


          I have a servlet that needs to call a method defined in another servlet. How can it be done?
    I have tried the getServlet() method in com.oreilly.servlet.ServletUtils, but i ran into some problems and i was wondering if there's any other way to do it?
    Any help would be greatly appreciated. Thx!!
  2. Hi,
       getServlet() method of ServletContext interface was depricated.
    Please refer servlet 2.2 API there you can see the method getRequestDespatcher() of ServletContext
    which is used to get the RequestDespatcher object.
    Using RequestDespatcher object you can forward a request to any other servlet.

  3. invoking methods from another servlet[ Go to top ]


    If you do not want to forward to the servlet whose method you wish to invoke, you should put the method(s) in a standard java class and bind an object of that class either to the ServletContext or the Session object, depending upon the scope.

  4. You can include the contents of another servlet using the same approach, it's just a different method if memory serves.

    Servlet includes were part of the 2.2 spec.