• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to dispaly Blob (image) in servlet

 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I got a Blob out of the MySql DataBase like:
if(rs.next()){
i = rs.getInt(1);
Blob b=rs.getBlob("img");


How do I show this in a servlet now?
I tried doing: response.setContentType("img/gif");
ServletOutputStream sout = response.getOutputStream();
sout.write(b);
sout.flush();
sout.close();

But It does not work. Please help.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bikash Jha:
But It does not work.


This is not a useful description of the problem. How is it not working?

P.S. Check your MIME type.
 
Chris Corbyn
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you gone directly to the URL which accesses the servlet that outputs this? What do you see? Errors, or garbled nonsense? The mime type is ("img" ?) wrong that's for sure.
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an old, related post that may be of help:

http://www.coderanch.com/t/291337/JSP/java/Display-database-BLOB-jsp
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!