• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing, retrieving, displaying images

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm working on a project where I want to store gif or jpg images into a MySQL database using the BLOB data type. That part is easy. I got that figured out. What I need to know is how do I store and retrieve the image to and from the database using which Java data types (ImageIcon maybe)? Also, ordinarily to display an image in HTML you use the <img src="..."> tag. Its' src attribute requires a string pointing to an image file in a directory structure. But in this case, I'm not retrieving the file from a directory tree, I'm getting it straight from a database. So in the JSP page how do I display an image retrieved from a class that got the image from the database? I need to see an example of how this is done.

Please advise,

Alan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64962
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The src attribute of your img tag will address a servlet that will read the data from the db, set the content headers as appropriate, and stream the data to the response.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
The src attribute of your img tag will address a servlet that will read the data from the db, set the content headers as appropriate, and stream the data to the response.


Do you have some sample code of a servlet and sends back a response for an image? I need to see an example of how it's done.

Alan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64962
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Courtesy of Ben Souther.

Check out his "Simple Stream" example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic