-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------
Durga Panda wrote:
> -----------------------------
> Please read the FAQ!
> <http://java.apache.org/faq/>
> -----------------------------
>
> basically the requirement is to show an image which is in a byte[] and which
> was never in a file ( directly saved on a byte[] from upload from
> multipart/form-data and never saved on a file due to i/o response problem
> and name conflict problem) and this byte[] picture is to be displayed on a
> html using an img tag... please let me know how i can display this picture
> directly from the byte arry...
> thanks...
> (panda)...
>
The important issue for you to remember is that the request for the HTML page
that references this image, and the request for the image itself, are
***separate*** requests. You cannot combine them in the same response.
To understand this, consider that you have a servlet at
http://www.mycompany.com/servlet/PageServlet that creates an HTML page, with the
following contents (among other stuff):
<img src="http://www.mycompany.com/servlet/ImageServlet">
When the browser sees this, it will submit a separate request for the image.
Your ImageServlet's doGet() method would look something like this:
byte image[] = ....; // Construct the byte array somehow
response.setContentLength(image.length);
response.setContentType("image/gif"); // Or image/jpeg depending on
format
ServletOutputStream os = response.getOutputStream();
for (int i = 0; i < image.length; i++)
os.write(image[i]);
os.flush();
It is possible to serve both the page and the image from one servlet, but you
will need to use some part of the request (say, a query parameter or extra path
information) to determine whether the page or the image is being requested. If
you do this, it will still be two separate requests.
Craig McClanahan
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]