I am implementing an applet module which receiving an object sent from a servlet.
The following is used to setup connection.
private URLConnection getServletConnection(String hostName) throws MalformedURLException,
IOException {
URL urlServlet = new URL(hostName);
URLConnection con = urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-java-serialized-object");
return con;
}
The following is the code segment for receiving "result object" from servlet.
// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
result = (ProcessingResult) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
System.out.println("Received data 1" );
result.serialize(System.out);
PrintStream tmp = new PrintStream(new File("testReceivedProcess.xml"));
result.serialize(tmp);
At present, the code can work. In specific, the line of
result.serialize(System.out);
is able to output the generalized XML file in the Eclipse console. The corresponding XML file can also be generated through
PrintStream tmp = new PrintStream(new File("testReceivedProcess.xml"));
result.serialize(tmp);
Currently, I want to directly output this XML file to the browser. How to do it? Thanks.