Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

thumbnail in jsp  RSS feed

 
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...
 
Ranch Hand
Posts: 893
Java Tomcat Server Ubuntu
  • 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
 
Marshal
Posts: 67226
169
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
Java Tomcat Server Ubuntu
  • 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
Marshal
Posts: 67226
169
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
Java Tomcat Server Ubuntu
  • 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
Marshal
Posts: 67226
169
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
Java Tomcat Server Ubuntu
  • 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.
 
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.
 
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!