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 communication on different servers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet communication on different servers." Watch "servlet communication on different servers." New topic
Author

servlet communication on different servers.

satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

Hello everyone,

Greetings !! hope you all doing great with your kith and kin.

I have a new problem(not actually a problem but something new to learn about ) ,i am doing some manipulations with one servlet ,say

ServletOne, now i have ServletTwo on different tomcat server.

now i want to send a request from ServletOne to ServletTwo and want a response back from ServletTwo to ServletOne.

what is best way to achieve it. I am using URL CLass for this.but i want to send response back from ServletTwo to ServletOne with some values. will sendRedirect will help in this,in case i need some values with it.

Please suggest.

Thanks
Maks Besida
Greenhorn

Joined: May 26, 2011
Posts: 13

Have you tried to use RequestDispatcher#include?
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

for interservercommunications on this level, i use the HttpURLConnection.

for writing use *.getOutputStream();

for getting the response, use *.getInputStream()

for example, you can send an xml, and receive an answer, also as xml.

Search for the specifications of this one, you'll find it!
satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

olivier dutranoit wrote:for interservercommunications on this level, i use the HttpURLConnection.

for writing use *.getOutputStream();

for getting the response, use *.getInputStream()

for example, you can send an xml, and receive an answer, also as xml.

Search for the specifications of this one, you'll find it!



can you please share some piece of code for better understanding. this would be great help.

Thanks in advance
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

here is a quick and dirty example :

satnam singh negi
Greenhorn

Joined: Aug 13, 2011
Posts: 25

olivier dutranoit wrote:here is a quick and dirty example :



Thank you so much for quick responses,
The problem is that we are trying to implement browser re-direction without a browser, which is not a good idea. In order to invoke the servletTwo on other server , we need to work with help of browser redirections at this phase.

Its like there are three different server, server1 is requestor server from where all the incoming request will come to server2 which is the main server where all the request validations are taken care of. my situation is while validating that request means in between the code i need to reach to server 3 ,collect the response from there and again return to server 1.

this is the whole scenario. how can implement browser redirection in between java code.

Please suggest, and moreover thanks for the time to read the post.

cheers.

 
Consider Paul's rocket mass heater.
 
subject: servlet communication on different servers.
 
Similar Threads
How to transfer object from servlet tp JSP and back to Servlet
How to transfer object from servlet tp JSP and back to Servlet
Servlet method execution sequence
can we put requestattribute in filter
Servlets - Request - Threads question?