0

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.

Edited by winecoding: n/a

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by NormR1
0

Do you want its display to replace the page with the applet
or to be displayed on the same page with the applet, say in a textfield?

0

I would like to open an browser, and displaying the generated XML file automatically. I do not know how to do it based on my current implmentation. Thanks.

Do you want its display to replace the page with the applet
or to be displayed on the same page with the applet, say in a textfield?

0

Ok, you want the output generated by the Applet to go into a new page in the browser.
That will take some research. I have no ideas right now.
The only approach I can think of would be to use some JavaScript.

Edited by NormR1: n/a

0

The first idea:
Javascript can call an Applet. I'm not sure an applet can call a javascript function.
Javascript can create new pages for a browser.
Have a javascript method poll the applet (if applet can not call JS) and ask for the data to be written to the new page. When the applet has the data it returns it to the JS code which creates the new page for the browser.

0

Thanks, NormR1

By googling, I found sth like

URL url = new URL(getCodeBase().getProtocol(),
                      getCodeBase().getHost(),
                      getCodeBase().getPort(),
                      "test/html");
                 getAppletContext().showDocument(url, "testReceivedProcess.xml");

Which is claimed to be able to open a new browser window. I put them into my code. It was running without incurring any error. But, no browser was launched. I think I might setup parameter wrong. Do you have any idea using this code segment?

The first idea:
Javascript can call an Applet. I'm not sure an applet can call a javascript function.
Javascript can create new pages for a browser.
Have a javascript method poll the applet (if applet can not call JS) and ask for the data to be written to the new page. When the applet has the data it returns it to the JS code which creates the new page for the browser.

0

How were you executing the applet?
Normally the applet would be executing on a page in a browser.
The call to showDocument would request the browser to show the page at the passed URL.

Did you read the API doc for the showDocument method?

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.