• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thumbnail in jsp

 
Confused
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to display an image in jsp .. the image is stored in the database as image...
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following link will help you.

I've used this link for solving the same problem

Image in jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you explain that more with an example. Maybe I could also use your advice?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you like more the following solution

Using dynamic images in a JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ben it is a very useful link
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic