File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet-Servlet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet-Servlet communication" Watch "Servlet-Servlet communication" New topic
Author

Servlet-Servlet communication

Ashutosh Shinde
Ranch Hand

Joined: Jun 07, 2001
Posts: 42
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:
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Jun 07, 2001
Posts: 42
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
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You could always use a shared database server to share data among servers.


James Carman, President<br />Carman Consulting, Inc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet-Servlet communication
 
Similar Threads
Is this possible?
CGI and Java
connection pooling implementation
How to pass parameters from one JSP to another JSP
init method of servlets