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 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 Spring in Action this week in the Spring 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: 637
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: 12803
    
    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: 637
Hi William,
Thanx A bunch for your reply will go thru both classes(interfaces)

Cheers
-Praful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Response Back in calling Servlet