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");
//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();
//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();
//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