• 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-Servlet communication

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I have 2 servlets on 2 different web servers. I want to pass two parameters between these servlets. One is an Object and other is a String. The processing at the second servlets will be based on the String variable passed. Also I want to use the POST method.
If I use the URL Connection for establishing the connection how should I pass the parameters ?
How should I retrieve the parameter at the other servlet ?
I am thinking of using the ObjectOutputStream for passing the Object.
Any suggestions would be welcome.
Thanks for your time,
ashutosh
:roll:
 
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
Serializing the String will certainly work. I feel sure that you don't mean a literal java.lang.Object since that would carry no information. Is your object serializable?
Bill
 
Ashutosh Shinde
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey William,
Thanks for the reply.
I am using the URL Connection to write a Object from the WebServer 1 to the WebServer2. I have used the ObjectOutputStream for this. What i need to do now is to pass a byte Stream(which used the object passed to it above) that is generated at the WebServer2 to the WebServer1 . I tried to use the DataOutputStream, but for some reason I started getting a Socket Exception. I dont know why! So, i replaced the DataOutputStream with a ObjectOutputStream for writing the byte array which i have now put in another serialisable object. I am now able to retrieve the byte array from this object...
Although I have achieved what i wanted i guess there should be a better way of communication between the 2 servers.
I also looked at redirect but was not sure if i can pass a object parameter through this redirected call...
Any suggestions would be most welcome..
Thanks,
Ashutosh
 
William Brogden
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
Using ObjectOutputStream to send a byte array should be very efficient, so it looks like you found a good solution.

I also looked at redirect but was not sure if i can pass a object parameter through this redirected call...


Passing anything significant in a redirect sounds pretty chancy to me.
Bill
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could always use a shared database server to share data among servers.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic