• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Response Back in calling Servlet

 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,
Thanx A bunch for your reply will go thru both classes(interfaces)

Cheers
-Praful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic