Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP Applet to Servlet to HTML in Browser

Status
Not open for further replies.

BZJavaInst

Programmer
Jan 17, 2001
67
US
I was able to create an Applet that sends Data in an Serialized Object to a Servlet and then return the data back to the Applet. I am using both the ObjectOutputStream and ObjectInputStream to do this. However when I tryed to build HTML in my doPost and send it back to the Browser, the HTML did not execute. Only the Applet remained in the Browser. Does any know why this is?

I am using the JSDK2.1. I also tryed using the PrintWriter with the response.getWriter() and I had no luck. It does work if I call the doPost from an HTML instead of the Applet. I even tryed it with response.getOutputStream() with no luck.

sample code:
// htmlPage is a String with the HTML code

PrintWriter outputBR = new PrintWriter(response.getOutputStream()); // or response.getWriter();
response.setContentType("text/html");
outputBR.println(htmlPage);
outputBR.close();

If I use in the Applet a BufferedReader and get the Servlet response, the String that is returned by my readLine() shows the HTML code sent, but I need it to execute in the Browser and not be sent to the Applet.

Can any Help? Is this possible? Thanks, Brian.
 

AFAIK the only way an applet can tell a browser to load
a page is getAppletContext.showDocument (URL) ... but
you said you were doing a post, which i'm pretty sure
you can't do with showDocument()

if this is true, then you have two options

a) use all your existing code, and have applet dump
http output to a local tmp file (if your security
context allows it)
... or ...

b) servlet dumps stuff to a tmp file under web svr
root, and sends URL to tmp file (or cgi, whatever)
to applet ... applet then calls showDocument(URL)

dave
 
Thanks for the suggestion Dave,

I was just hoping I could avoid temporary files by having he Servlet create the HTML and submit it to the Browser. I thought about using HTMLDocument also to create the HTML text. This would allow Dynamic pages, but unfortunately I can not get the applet to be over ridden by the new HTML. Many sample Servlets I see only create the HTML and send to the Browser, but none use an applet at the same time.

Your suggestion sounds like the next best option.

Thanks again,
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top