Solved

HOWTO invoke a method on another Servlet from my Servlet?

Posted on 2001-08-14
7
320 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 35 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 103
eclipse compiler vs Installed JREs option 3 77
ForLoop Example 3 40
Eclipse with gitlab 1 15
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

861 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now