my dog learned polymorphism*
The moose likes JSP and the fly likes thumbnail in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "thumbnail in jsp" Watch "thumbnail in jsp" New topic
Author

thumbnail in jsp

Confused
Ranch Hand

Joined: Jan 24, 2006
Posts: 54
i want to display an image in jsp .. the image is stored in the database as image...
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
The following link will help you.

I've used this link for solving the same problem

Image in jsp


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

DO NOT use a JSP to stream the image as described in that article. That's a house of cards that will fall on you hard. Use a servlet instead.

You can use an <img> tag in the JSP that specifies a src attribute that references the servlet.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Could you explain that more with an example. Maybe I could also use your advice?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

JSPs should never be used to serve non-text data. Please see this article to find out why.

Rather, a servlet -- possibly using the help of other classess -- should be used to get the image data and serve it as the response. Be sure to set the appropriate response headers accordingly.

In your HTML page -- whether it's generated from JSP or not is moot -- you would use an <img> tag just like any other image. Except that the src attribute of the <img> tag references the image-serving servlet rather than an image file.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
So you like more the following solution

Using dynamic images in a JSP.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

That's the idea, but that article is 7 years old and shows it. Statements like "you could do the database access in the JSP itself" have no place in modern architectures.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Bear Bibeault thanks for your reply

I understand all my database access is done at one helper class.

I will use this idea for making a utility servlet which will retrieve the images for the different jsp's.

Thanks for your input.
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
I also face the same problem. I want to display these images as thumbnails dats means i want to show dat by reducing it size, height and width.


Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Dilshan Edirisuriya:
I also face the same problem. I want to display these images as thumbnails dats means i want to show dat by reducing it size, height and width.


This thread might be of interest to you:
http://www.coderanch.com/t/345045/GUI/java/Resizing-Image-Java-vs-PHP


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
Thank you Ben it is a very useful link
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Your welcome.

Also, if you want to see an example app that uses a servlet to stream images to a browser, I have one on my site.
http://simple.souther.us
Look for Simple Stream.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thumbnail in jsp
 
Similar Threads
WAR Deployment - Images not loading
Previous JSP Image not retaining
Write an Image From Servlet
image not displaying in tomcat server
Iterating a Array in Struts2