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

Servlet calling a another servlet on different context.

jhonty jhonty

Joined: Jan 05, 2004
Posts: 1
I have two servlets running in different webserver and i want to establish a connection and i need to pass an object from servlet1 to servlet2.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Use getServletContext().getContext("/context_folder") to get the context of the second application and pass the object.
The code may look like :
you can retrieve the object from request.

- Varun
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
Servlets where not designed to make remote calls (from one JVM to an other) by default. This sounds more like a design issue than a servlet issue.
You may want to consider taking the business logic in the servlet to be called and placing it into an EJB. Both servlets (and any other client down the road) will just call the EJB when that functionality is required.
There really is no way to pass an Object from one servlet to an other, and you probably shouldn't design a system to do so. As stated above, you may look up an other J2EE app and pass the Req/Res to a URL in that app, but as far as passing an Object around, that is what EJBs are for.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Since that is a "different webserver" you are talking about, you might use a Java Message Service - it has provision for serialized objects as messges and may be simpler than EJB. Of course a direct socket connection between the two servers could also be used for the simplest one-shot.
You might tell us more about the volume of traffic, reliability requirements, size of the object, etc. as there are LOTS of possible solutions.
[ January 05, 2004: Message edited by: William Brogden ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

"jhonty jhonty"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy.
You can change it here.
Thanks! and welcome to the JavaRanch!
I agree. Here's the link:
subject: Servlet calling a another servlet on different context.
It's not a secret anymore!