• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet calling a another servlet on different context.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic