I am trying to open a browser window from a web server (using javascript) with a xml document sent via a xmlhttprequest response. The application uses javascript, so java 1.5 is no use here.
The code of the xmlhttp post is this:
String strSoap = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soap:Body>" +
xml_body
"</soap:Body>" +
"</soap:Envelope>";
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setRequestProperty("SoapAction", some_action);
connection.setRequestProperty("Man", "POST url HTTP/1.1");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setAllowUserInteraction(true);
connection.setFollowRedirects(true);
java.io.DataOutputStream printout = new java.io.DataOutputStream (connection.getOutputStream());
printout.writeBytes(strSoap);
printout.flush();
printout.close();
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
Anothe posibility it will be to make the xmlhttprequest from the client side, which is the better option?
Make the xmlhttprequest from the client side. When you receive the response, open a new window (
window.open()).Using client-side JavaScript, you can then fetch the response from the original window and print it out in the new window.
For example, suppose the JavaScript variable
myXmlcontained the text response to the xmlhttprequest in the original window then the executingdocument.write(window.opener.myXml)in the new window would write the response there.