Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

jsp images (img) and binary data (png)

Thread view: 
grasp06110 - 13 Dec 2007 13:47 GMT
Hi Everybody,

Looking into this topic I have found many ways of dynamically setting
the src attribute of an image tag to retrieve binary data from a data
source for an image.

I have not been able to find a way that does not require a round trip
to the server for each image.  Is it possible to avoid this?

For example, I have data for 1000 images in a database I would like to
sent to a client upon request.  Since I have all of the data in hand I
would like to send it all as part of the same response and have each
of the images rendered on the client (as well as a bunch of other HTML
of course) with out the client needing to ask for each image
individually.  I would think that this would represent a substantial
performance improvement as the conversation would go something like:

client: may I have everything I need to render that page that has 1000
images in it?
server: here's all the data for everything, have fun

instead of:

client: may I have that page with 1000 images in it.
server: here's the html
client: may I have the data for the first image?
server: here's the data for image 1
client: how about image 2?
server: here ya go
client: and image 3?
server: here ya go
client: and image 4?
server here ya go
...

As usual, any help would be greatly appreciated.

Thanks,
John
Nigel Wade - 13 Dec 2007 15:18 GMT
> Hi Everybody,
>
[quoted text clipped - 35 lines]
> Thanks,
> John

Zip up the images, and send the zip file. In the client, read the images from
the zip.

That's what I do for displaying a 24hr "movie" of ionosonde data, with one image
every 5 minutes. The client (an applet in this case) requests the images via a
cgi-bin URL which specifies the date. The cgi creates a zip archive of the
images for that date and responds with the necessary HTTP for the client to
understand it, in this case it's PHP:

header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Fri, 4 Nov 2005 00:00:00 GMT");
header("Content-Type: application/zip");
exec("/usr/bin/zip -qj $tmpfile $Directory/*.gif");
passthru("/bin/cat $tmpfile");

The important part is "Content-Type: application/zip", the other bits are to try
to prevent client side caching. The last two commands create a temporary zip
file of the GIFs in a directory, which is then streamed back to the client.

The client requests the zip file by opening the correct URL, which it reads as a
ZipInputStream:

  URL url = new URL("url of cgi-bin");
  ZipInputStream zipStream = new ZipInputStream(url.openStream());

and from there the client can access the images in the ZipInputStream. In my
case I always want to read them in sequence. Random access to a zip might be
more problematic.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

grasp06110 - 13 Dec 2007 18:39 GMT
> > Hi Everybody,
>
[quoted text clipped - 71 lines]
> E-mail :    n...@ion.le.ac.uk
> Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Hi Nigel,

Thanks for the help!

I'm still not sure what to do about getting the images rendered in the
jsp on the client once I have the data on the client.  The only thing
I've been able to find basically uses an img tag and sets the data to
some url.  I'm not sure how to go from img src=somefile to img
src=data from an input stream.

John
grasp06110 - 13 Dec 2007 18:41 GMT
> > > Hi Everybody,
>
[quoted text clipped - 83 lines]
>
> John

Sorry, I should be more clear (I didn't see the applet part).  Is
there a way to do this in an html page with out using an applet?

John
Lew - 14 Dec 2007 02:20 GMT
>> I'm still not sure what to do about getting the images rendered in the
>> jsp on the client once I have the data on the client.  The only thing
>> I've been able to find basically uses an img tag and sets the data to
>> some url.  I'm not sure how to go from img src=somefile to img
>> src=data from an input stream.

> Sorry, I should be more clear (I didn't see the applet part).  Is
> there a way to do this in an html page with out using an applet?

Use an <img> tag that refers to your own servlet that emits the image.

<img src="/Imager?name=foo.jpg" />

The Imager servlet will read the input stream and emit the image.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.