Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HOWTO invoke a method on another Servlet from my Servlet?

Posted on 2001-08-14
7
Medium Priority
?
331 Views
Last Modified: 2013-11-24
Hello!

How can my Servlet invoke a public method on another Servlet?

Thanks.
0
Comment
Question by:jussara
7 Comments
 
LVL 1

Expert Comment

by:dviji
ID: 6386015
By using " InterServlet Communication" we will achive it.

Example:-

ServletContext sc = getServletConfig().getServletContext();
Enumeration  servletNames = sc.getServletNames(); //will return the available servlet names
MyServlet myServlet = (MyServlet)sc.getServlet("servletName "); //get the MyServlet instance from ServletContext
String name = myServlet.getNames(); //execute the public method.


...dviji





0
 
LVL 7

Expert Comment

by:tomboshell
ID: 6387238
Hmmm, interesting.  I was reading that the method 'getServletNames()' is deprecated.  It wont be along much longer.  So, I would guess in such a situation the use of reflection would work.  But it is an interesting problem.  

Tom
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 140 total points
ID: 6388476
My understanding, also. Prior to Servlet 2.1 it was possible for one servlet to call the methods of another servlet directly. A strictly-conforming 2.1 engine will not allow this. Instead, there are other mechanisms to accomplish "servlet-chaining". For details of both the pre-2.1 and post-2.1 techniques and examples, have a look at:
    http://novocode.de/doc/servlet-essentials/chapter3.html

Best regards,
Jim Cakalic
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:jwenting
ID: 6409120
interservlet communication was deprecated and will be (has been?) removed in later versions because of security reasons.

The best way to achieve it is by having the servlets call one another over HTTP, and having the service method throw back the response based on the parameters passed (passing in the function to be called as a parameter, and parameters to it as other parameters for example).
0
 

Expert Comment

by:CleanupPing
ID: 9061865
jussara:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 9072392
Recommendation: points to jim_cakalic
0
 
LVL 20

Expert Comment

by:Venabili
ID: 9330390
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for jim_cakalic

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question