This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Getting Response Back in calling Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting Response Back in calling Servlet" Watch "Getting Response Back in calling Servlet" New topic
Author

Getting Response Back in calling Servlet

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
Hi All,

I have an following requirement

1 Browser makes an request to Servlet in Sever1
2 Servlet in Server1 will make an HTTP post request to Servlet in
server2 with one paramter called reqData which will be an xml
format data as follows
<emp>
<emp-no>10</emp-no>
<emp-name>Bond</emp-name>
</emp>

3 Now Servlet on server2 will read this data and send back the response
in xml format as
<response>
<response-code>0</response-code>
...
...
...
</response>

I am clear till read reqData and generate response Data (3).

but how do I get response data back in servlet on server1 and display the result on browser ?

I guess I need to use some way to call servlet in sever2 other then simply using sendRedirect.

kindly help

Cheers
-Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
2 Servlet in Server1 will make an HTTP post request to Servlet in
server2

If you make a POST request to server2 with a HttpURLConnection, you will get the results back in the response. You can read the response headers and get the response body with separate methods. The headers will probably have useful information and the stream representing the body will have the xml.
Look at the methods in java.net.URLConnection and HttpURLConnection.
Bill
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
Hi William,
Thanx A bunch for your reply will go thru both classes(interfaces)

Cheers
-Praful
 
Don't get me started about those stupid light bulbs.
 
subject: Getting Response Back in calling Servlet
 
Similar Threads
copy data between two different servers
Doubt in servlet program using eclipse IDE
Communication Between two servers
HTTP push
Response Tracking in the Web Services is possible if reached client or not?