Basically you want to have the image data served by a
servlet from the byte array instead of the web server from a file. You have to arrange that the URL in the <img> tag points to a servlet that has the byte array. You have to set the response content-type to "image/gif" and the content-length to the byte[].length. See the HttpServletResponse API.
You MUST get an output stream instead of a writer so the bytes will go out unaltered. Then just write the byte array and close the stream.
This is a common item in many servlet books and you can find plenty of related discussions in older threads here.
Bill