Amy,
I think this error means that there is no response from that URL. Try
accessing that exact URL with a browser and see what message you get. Also
you might try setting the content type to "application/octet-stream" and see
if that helps.
We are successfully sending objects to and from a servlet using HTTP, let me
know if you need more help.
Rob Griffin
[EMAIL PROTECTED]
Quest Software Pty Ltd
303 High St, Ashburton, Vic. 3147 Australia
Phone: +61 3 9811 5253 Fax: +61 3 9885 0116
http://www.quests.com
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Amy Wan
Sent: Wednesday, 14 July 1999 2:57
To: [EMAIL PROTECTED]
Subject: sending binary data\byte from servlet to applet
I am trying to send binary data from servlet to applet
My servlet read an image from the database. The type of that image that I
got from the database is InputStream
So I tried to write to the OutputStream in servlet in order to send the data
back to the applet by using the following:
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
byte[] buf = new byte[8000];
int n = 0;
while ((n = in.read(buf)) > 0)
{
out.write(buf, 0, n);
}
out.flush();
Then in applet, i used the following to read the returned data
In the applet:
-------------
Image img; // A member variable of the applet.
InputStream in = url.openStream(); //<----my program died here
byte[] buf = new byte[8000];
ByteArrayOutputStream bout = new ByteArrayOutputStream(30000);
int n = 0;
while ((n = in.read(buf)) > 0)
{
bout.write(buf, 0, n);
}
bout.close();
in.close();
byte[] imageBytes = bout.toByteArray(); //by using the byte array, I should be able
to create the image again
--------------------------------------------------------
However, the program was dead at InputStream in = url.openStream();
saying java.io.FileNotFoundException: http//localhost:8000/servlet/testDBServlet
where testDBServlet is the servlet that I wrote.
Anyone knows why there is such an error and how to solve it?
Thanks a million.
___________________________________________________________________________
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