Hello everyone,
I have searched all the information about how to display images from database using
jsp in this forum, but none of the problems is samilar to mine.
I used a
servlet class to retrieve the image blob data and wrote it to the response outputstream.
-------------------------------------------------------------------
String getResourceSql = "select content from tblContent where contentID = 9";
ResultSet docRs = stat.executeQuery(getResourceSql);
if (docRs.next()){
byte[]
doc = (byte[])(docRs.getObject("content"));
System.out.println("data length " + doc.length);
ServletOutputStream ostr = response.getOutputStream();
ostr.write(doc);
ostr.flush();
ostr.close();
System.out.println("test");
}
---------------------------------------------------------------------
And after, I wrote a jsp file to call the servelt to display the image as below:
<html>
<body>
<img src="/meg/ImageServlet?contentId=8"/>
</body>
</html>
I could get the servlet
test message (data length and "test" string ) printed out in
Tomcat dos window, which means that the servlet was called successfully. However, the image could not be displayed in the jsp page (only a red cross). I wonder what is wrong with my code?
Thanks a lot in advance!