File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Calling servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling servlets" Watch "Calling servlets" New topic

Calling servlets

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi all,
I have a servlet in one application "A" and i want to call another servlet in an application "B" from the first servlet. How do i do this.
if possible pl tell me the same in case of EJBs too as to how to call an EJB which is existing in another application

Thanx in advance
Shripad Bokil

Joined: Jan 30, 2001
Posts: 13
Regarding calling the servlet...
If your servlet 'A' has a html code embeded in out.println("....")...then you can specify the servlet "b" in the action part of the form...i.e....
<form method = get or post action ="Your servlet path here">
you can use sendRedirect(servlet path here) call servlet"b"
In case of EJB you can call another EJB by specifying the correct JNDI name in lookup for the second EJB.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Shripad,
I think U have overlooked the question.Am asking how to call a servlet which is in web application "B" from a servlet which is in application "A"
and How do i call an EJB which is in application "B" from an EJB which is application "A"
Suneel Setlur
Ranch Hand

Joined: Nov 26, 2000
Posts: 202
You could use ServletContext to link call the servlet.
With an EJB, the first EJB must communicate to the second, as an EJB client would. Get the reference of the Home Object and then access it.
[This message has been edited by Suneel Setlur (edited January 31, 2001).]

Karthi Bala
Ranch Hand

Joined: Jul 27, 2001
Posts: 48
Hi suneel,
I tried the same with this code.
But I could succeed it calling the servlet ViewMiniPoll which is different in Web application.I am using JRun 3.0
Thanks in advance

Karthi Bala<br />SCJP 1.2, SCWCD 1.3, SCWCD 1.4, SCDJWS (Awaiting Result)<br /> <br />Where there is a will,there is a WAY.
Dmitriy Pavlyuk
Ranch Hand

Joined: Mar 25, 2001
Posts: 33
It is so easy to call servlet and receive it's output stream (if necessary). See it in the questions of the week in
I agree. Here's the link:
subject: Calling servlets
jQuery in Action, 3rd edition