Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to dispaly Blob (image) in servlet  RSS feed

 
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.
 
Author and ninkuma
Marshal
Posts: 66475
160
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.
 
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.
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!