james henderson
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.htm l. 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.getM essage());
}
try
{
AppletContext browser = getAppletContext();
browser.showDocument(new URL("file:///" + sFileName), "_blank");
}
catch(MalformedURLExceptio n ue)
{
System.out.println(ue.getM essage());
}
Any help appreciated.
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.getM
}
try
{
AppletContext browser = getAppletContext();
browser.showDocument(new URL("file:///" + sFileName), "_blank");
}
catch(MalformedURLExceptio
{
System.out.println(ue.getM
}
Any help appreciated.
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 ?
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
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