aspose file tools*
The moose likes JSP and the fly likes Storing, retrieving, displaying images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Storing, retrieving, displaying images" Watch "Storing, retrieving, displaying images" New topic
Author

Storing, retrieving, displaying images

Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 237
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

Joined: Jan 10, 2002
Posts: 61654
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 237
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

Joined: Jan 10, 2002
Posts: 61654
    
  67

Courtesy of Ben Souther.

Check out his "Simple Stream" example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing, retrieving, displaying images