Hi there
Try this:
In your original Applet, use showDocument() to open a new window with an
html page in it.
This html page contains a second Applet with your File Dialog choice in it
(I'll call it Applet 2).
In Applet 2, when the user presses the OK button or whatever, you call your
Servlet (probably using code similar to what I sent you below).
The response, which is the contents of a file, can then be displayed as you
want it in Applet 2 (for instance in a TextArea), or you could completely
replace your Applet 2 with a new html page - depends what you want to do
afterwards.
Hope this helps
Ken
Oggetto: Re: Oggetto: Re: Oggetto: servlets and applets
hi again,
i was out of my office for a few days so i could not try your option until
today.
I think there is a misunderstanding because in my applet a need to open a
new browser window because a GUI will be need where users select the the
file that will be read.
(it means showDocument() method is needed.)
but when user enter ok in the new opened window the content of the file.
so i need a servlet applet communication but using two browser.
or you suggest to solve the problem in a different manner,
thanks,
serdar
----- Original Message -----
From: "Ken Barron" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 11:58 AM
Subject: Oggetto: Re: Oggetto: servlets and applets
> You create the streams in the Applet, because you're connecting to your
> Servlet, sending it parameters (such as the filename, user & password if
> necessary, etc), and then reading the response from the Servlet (ie. the
> contents of the file you want to display).
>
> You could use something like this in your Applet :
>
> java.net.URL u = new java.net.URL(serverAddress);
> java.net.URLConnection c = u.openConnection();
> c.setDoOutput(true);
> c.setDoInput(true);
> c.setUseCaches(false);
> c.setRequestProperty("content-type","application/octet-stream");
>
> file://Prepare the call to the servlet
> java.io.ObjectOutputStream oos = new
java.io.ObjectOutputStream(c.getOutputStream());
> oos.writeInt(fileID);
> oos.writeUTF(user);
> oos.writeUTF(password);
> oos.flush();
> oos.close();
>
> file://Read the response from the servlet
> java.io.ObjectInputStream ois = new
java.io.ObjectInputStream(c.getInputStream());
> int request = ois.readInt();
> if (request == Consts.QUERY_WITH_RESULTS) {
> fileContents = (java.util.Vector)ois.readObject();
> file://blah blah blah ...
> }
>
>
>
>
>
>
>
> Serdar BOZDAG <[EMAIL PROTECTED]>@JAVA.SUN.COM> il 17/07/2002
> 10.38.14
>
> Per favore, rispondere a "A mailing list for discussion about Sun
> Microsystem's Java Servlet API Technology."
> <[EMAIL PROTECTED]>
>
> Inviato da: "A mailing list for discussion about Sun Microsystem's
Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>
>
> Per: [EMAIL PROTECTED]
> Cc:
>
> Oggetto: Re: Oggetto: servlets and applets
>
>
> thank you i think the second option will work, but can you be more
precise.
> can you give a simple code example or sth like that. (where will I create
> the ObjectOutputStream and ObjectInputStream? in the applet or servlet?)
>
> best regards,
> serdar
>
> ----- Original Message -----
> From: "Ken Barron" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, July 17, 2002 11:04 AM
> Subject: Oggetto: servlets and applets
>
>
> You have two basic options here:
> 1. Your applet calls the Servlet with a showDocument. This means the
> output of the Servlet will go directly to the browser window called by
> showDocument (ie. NOT to your Applet).
> 2. Use an ObjectOutputStream to write to the Servlet and an
> ObjectInputStream to read the output of the Servlet directly in your
> Applet.
>
> A third option could be to create a completely new Applet inside your
> Servlet, wrap it in html, and ouput it to the browserwindow you're opeing
> with the showDocument of the first Applet.
>
> Hope this helps
> Ken
>
>
>
>
> hi,
> i have a question about servlets.
>
> in my applet I use showdocument method to open a servlet in a new
browser
> window. this servlet reads the contents of a file that user choose. this
> servlet needs the send the content of the file to the applet but since
> showdocument is used out.println() command in the servlet shows the
> content in the browser window.
>
> I may use urlconnection.connect() in applet to call the servlet but this
> time the wizard for file choosing will not be displayed. (servlet
displays
> a form in doGet method and get the contents of the form in doPost method
> and at the end of the doPost method result must be given to the applet.)
>
> my question is with showdocument method of applet can i get the result
> of a servlet. (i know quite an awkward question but i was not able to
> write more simpler)
>
> thanks in advance,
> serdar
>
>
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html