Sanika Kapoor wrote:

> Hi All,
>
> I already posted this problem but got no reply. Pl. if anyone has faced this
> problem before or has any clue about this, help me.
> I am facing some difficulties in displaying the image stored as binary type
> in the database.
> I retrieve this image in a BufferedInputStream and then store it in a byte
> array, but when I try to print this byte array, it is showing me some IO
> Exception.
>

To output binary data in Java (such as an image), you will need to use write()
calls rather than print() calls on the servlet output stream.  You don't even
need a byte array to do what you're trying.  A simple approach is this:

    response.setContentType("image/gif");    // Or whatever is right
    BufferedInputStream input = ... input stream to your data ...
    ServletOutputStream output = response.getOutputStream();
    while (true) {
        int data = input.read();
        if (data < 0)
            break;
        output.write(data);
    }
    output.flush();

>
> TIA,
> Sanika.
>

Craig McClanahan

___________________________________________________________________________
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

Reply via email to