GeeCON Prague 2014*
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
Author

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
Greenhorn

Joined: Jan 30, 2001
Posts: 13
Hi,
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">
</form>
otherwise....
you can use sendRedirect(servlet path here)...to 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"
Thanx
Suneel Setlur
Ranch Hand

Joined: Nov 26, 2000
Posts: 202
Hi
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.
Suneel
[This message has been edited by Suneel Setlur (edited January 31, 2001).]


Suneel
Karthi Bala
Ranch Hand

Joined: Jul 27, 2001
Posts: 48
Hi suneel,
I tried the same with this code.
getServletConfig().getServletContext().getRequestDispatcher("/servlet/ViewMiniPoll").forward(req,res);
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


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 java.sun.com
http://developer.java.sun.com/developer/qow/archive/140/index.jsp
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling servlets