You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "C.F. Scheidecker Antunes" <na...@antunes.eti.br> on 2005/08/05 00:44:10 UTC

Displaying a image from a MySQL Blob field

Hello all,

I am writing a Struts application which needs to read a database, fetch 
an image inside a blob field and display it in a JSP page in two 
different ways:
- Within a thumbnail size inside a column of a normal html <table>. 
Which means the image needs to be resized for displaying purposes.
All images inside this table cannot exceed a maximum height and width in 
order to have a neat display.
- And using the image original size.

Hence, I would like to ask if is there any example code on how to 
accomplish this task.
I guess the image size could be configured through html/javascript but 
what I wonder is how to read from the database and send it to the view 
component, the JSP
page to have it displayed.

I appreciate any inputs on this issue.

Thanks in advance,

C.F.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Displaying a image from a MySQL Blob field

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Because your dealing with a database, you may want to try the 
DownloadAction... it will deal with at least some of the details.  IIRC, 
somewhere on the Wiki is an example I wrote of using it specifically 
returning an object from a database.  II-DON'T-RC, ping me, I know I've 
done it at some point.

Frank

Wendy Smoak wrote:
> From: "C.F. Scheidecker Antunes" <na...@antunes.eti.br>
> 
>> I am writing a Struts application which needs to read a database, 
>> fetch an image inside a blob field and display it in a JSP page in two 
>> different ways:
>> - Within a thumbnail size inside a column of a normal html <table>. 
>> Which means the image needs to be resized for displaying purposes.
>> All images inside this table cannot exceed a maximum height and width 
>> in order to have a neat display.
>> - And using the image original size.
> 
> 
> When you put <img src="..."/> in an HTML page, the browser will make a 
> separate request to get the image.  I would map that request to a plain 
> old Servlet-- there's no reason to tie this to the Struts framework.
> 
> I do this now for an image that's generated by JFreeChart, but the same 
> thing applies if you're going to retrieve binary data from a database 
> and write it out to the browser.  Assuming you already know how to 
> retrieve the image from the database, ask Google about images and servlets:
>   http://www.google.com/search?q=java+image+servlet
> 
> I would get the full size image retrieval and display working first, 
> then think about how to do the thumbnails.
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Displaying a image from a MySQL Blob field

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "C.F. Scheidecker Antunes" <na...@antunes.eti.br>

> I am writing a Struts application which needs to read a database, fetch an 
> image inside a blob field and display it in a JSP page in two different 
> ways:
> - Within a thumbnail size inside a column of a normal html <table>. Which 
> means the image needs to be resized for displaying purposes.
> All images inside this table cannot exceed a maximum height and width in 
> order to have a neat display.
> - And using the image original size.

When you put <img src="..."/> in an HTML page, the browser will make a 
separate request to get the image.  I would map that request to a plain old 
Servlet-- there's no reason to tie this to the Struts framework.

I do this now for an image that's generated by JFreeChart, but the same 
thing applies if you're going to retrieve binary data from a database and 
write it out to the browser.  Assuming you already know how to retrieve the 
image from the database, ask Google about images and servlets:
   http://www.google.com/search?q=java+image+servlet

I would get the full size image retrieval and display working first, then 
think about how to do the thumbnails.

-- 
Wendy Smoak 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org