?
Solved

HOWTO invoke a method on another Servlet from my Servlet?

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

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

Thanks.
0
Comment
Question by:jussara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A solution for Fortify Path Manipulation.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

719 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