File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Dynamic Image Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Dynamic Image Creation" Watch "Dynamic Image Creation" New topic
Author

Dynamic Image Creation

Thomas Andrewsen
Greenhorn

Joined: May 26, 2006
Posts: 7
Hi All,
I want to dynamicaly create a image depending on the user logging in and is resource consumption, but i don't want to store the image in any temporary location, but it must be part of the dynamic html contetnt the user is viewing. The image won't be reused. Could anybody guide me on this.


regards,
Siva


Thomas Andresen
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yes, but I don't have any sample code on me.
Basicaly you write a servlet which accepts requests for images, dynamically generates one based on the user information, then encodes and streams it directly to the user. Nothing is stored locally.

Dave
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Look for link to addressbook in my signature. You will find class Challengeimage in sources. This class dynamically produces an image and display it on page. I use a front controller pattern, but you can consider this class as a servlet.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Thomas Andrewsen
Greenhorn

Joined: May 26, 2006
Posts: 7
But I want to embeed the image with html text
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Servers don't send text and images in one response.
Send the HTML with an image tag.
The browser will create a new request for the image and assemble the page.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Thomas Andrewsen
Greenhorn

Joined: May 26, 2006
Posts: 7
but the image is dynamically created, how to give link in the image tag
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Siva J"
Please change your display name back or your account will be deleted. Please don't play around with display names, we take them very seriously.

thanks,
Dave.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The servlet will return the image, so just link to the servlet in the image tag. The browser will send a separate request to load the image from the Servlet.
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
Servlet A returns


Servlet DynamicImageServlet sets the content type to image/png and streams the image to the client.

As other people have pointed out - the key here is it happens with 2 http requests, not 1.
Thomas Andrewsen
Greenhorn

Joined: May 26, 2006
Posts: 7
Hi All,
Thanks for ur help it sloved my problem.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
I'm about to be in the trouble he's been through... Hehehe I'll post on another thread.


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
 
Consider Paul's rocket mass heater.
 
subject: Dynamic Image Creation