This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display a database BLOB in a jsp

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the IMG tag takes a src path to an image to display it. But if you are getting the image from a database (or file system) it is not part of the web app. So how would you set the src param? Or is there another way to display it, since it is a stream of bytes when you get it from the database?
 
Stefan Evans
Bartender
Posts: 1777
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The standard approach is to have the src tag of the image point at a Servlet which is part of the webapp.
eg
<img src="/myWebApp/imageServlet?imageid=42"/>

That servlet is then responsible for loading the image, and sending it out via the ServletOutputStream.
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a shell to get you started:

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a big help. Thanks guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic