The
out variable is a
javax.servlet.jsp.JspWriter, which extends
java.io.Writer. Writer classes print/write character representations of data. So,
out.print(data[i]) is printing a character representation of each byte in the BLOB.
In order to display an image in a page, the browser is going to look for an <img> tag with the
src attribute pointing to a file on a server or URL, or as a download link.
If you really, really want to display the image in a page along with other text, the only way I can think of is to extract the BLOB and write it to an intermediate file, then reference that intermediate file in the
src attribute.
If you want get the
InputStream from the BLOB by calling
blob.getBinaryStream() (make sure your
jdbc drivers support BLOBs well), and feeding it to the
ServletOutputStream of the
response variable, it should allow a user to either download the image or view it in a browser window.