This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I my app I generate a xml document and write it to the output stream. But what I need to do is redirect the stream to a different server which will process the document for the user. How do I get this to work?
thanks for the fast answer. The other programmer uses PHP and does not want a Web Service. He wants the document in the redirected response. Any chance to do it like this?
Joined: Aug 10, 2001
OK, so the basic problem (as I understand it) is that you can't BOTH write to an output stream from a servlet and use sendRedirect to redirect the URI to a different server. So what you will have to do is:
(1) Build your xml document as a String. (2) Use an HTTPURLConnection to open a connection to the PHP program and send the String you just built. (3) Get a String back from the HTTPURLConnection and then place that on the output of your servlet.
By the way -- might I say that this is a horrible architecture for your web site. This will work, but the response time may not be good. If your servlet is the one that the user hits from their URL, then it should be doing the processing -- it may be in your interest to write your own code to just redo everything the PHP program does.