• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet calling a another servlet on different context.

 
jhonty jhonty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use getServletContext().getContext("/context_folder") to get the context of the second application and pass the object.
The code may look like :
getServletContext().getContext("/context_folder").getRequestDispatcher("servlet_or_jsp_name").forward(request,response)
you can retrieve the object from request.
HTH
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
[ January 05, 2004: Message edited by: William Brogden ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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!
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic