Solved

HOWTO invoke a method on another Servlet from my Servlet?

Posted on 2001-08-14
7
319 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

14 Experts available now in Live!

Get 1:1 Help Now