Link to home
Start Free TrialLog in
Avatar of james henderson
james hendersonFlag for United States of America

asked on

stream a string to a browser from applet

I have a java applet that gets a string containing html.  I need to stream this to a new browser window, which means using the getAppletContext() method.  At the moment, I write this string to a file on the pc (the applet is signed and is being allowed to do this), creating a new browser window with the getAppletContext, and giving it a URL of file:///c:/temp/myfile.html.  I would much prefer to stream the string to the browser, but I am totally stumped on how to do this.  

Here's what I'm doing now:

try
 {
     BufferedWriter out = new BufferedWriter(new FileWriter(sFileName));
     out.write(mo_Ap.getReport());
     out.close();
 }
 catch (IOException ie)
 {
   System.out.println(ie.getMessage());
 }

 try
 {
   AppletContext browser = getAppletContext();
   browser.showDocument(new URL("file:///" + sFileName), "_blank");

 }
 catch(MalformedURLException ue)
 {
   System.out.println(ue.getMessage());
 }

Any help appreciated.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>I would much prefer to stream the string to the browser, but I am totally stumped on how to do this.  

Not easy, since browsers don't do pipes. The only way i can think of is to get the applet to act as a mini web server and to get the browser to send a request to it
Why don't you transition to a jsp (instead of directly to the generated html) from the applet and let the jsp request for the html from the server ?
That would be much simpler and cleaner.

Or is all logic of creating the html residing in your applet ?
You could write the string to a div in the page using Live Connect
Avatar of DizzyDiz
DizzyDiz

Could you use a div tag instead of a separate window? Popups are generally considered annoying to many users anyway. Maybe a redesign of the page layout allowing for popup or dynamic changing sections (like Ajax) is more appropriate? Javascript is a much better choice than applets anyway if your primary interest is changing pieces of HTML. I'd use an Applet only as a last resort.
Avatar of james henderson

ASKER

Thanks for the replies.  The applet is a self-contained application.  The problem is that the jTextPane that can display html seems real finicky about perfect html, otherwise it doesn't display properly.  The only choice I seem to have to simply open a new browser window or try to find a browser class that I can include in my applet.  Thanks to all.  
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)