Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Display All images from a folder on a html/jsp page  RSS feed

 
ash neet
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have a folder named 'images' in my directory. the client will upload the images in this folder through FTP. after uploading, all the images that are present in this folder should be displayed on a html/jsp page. how do i do this?

Thanks in advance!!!

regards,

Ash neet
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the servlet which deals with the model, just read through the files in that folder and convert the list of files to a List of URL objects. (To do this you would have to arrange things so that files in that folder can be served directly by your HTTP server.) Put the List of URL objects into a request attribute and forward to the JSP.

In the JSP, do <c:for-each> over that List from the request attribute, and generate an <img> element for each entry of the List.
 
ash neet
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:In the servlet which deals with the model, just read through the files in that folder and convert the list of files to a List of URL objects. (To do this you would have to arrange things so that files in that folder can be served directly by your HTTP server.) Put the List of URL objects into a request attribute and forward to the JSP.

In the JSP, do <c:for-each> over that List from the request attribute, and generate an <img> element for each entry of the List.


Can you give me an example please?

Regards,

Ash neet
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you realise that displaying all the images on a web page downloads them to the client again?
You might want to consider generating "thumbnail" images of the uploaded files so that you can display them efficiently on your index page.

here is a basic shell of what I think it should look something like.

Build list of filenames to display



then on the jsp display an <img> tag for each file.


This is just a general pointer. Don't expect this to work out of the box.
Of course it depends completely on where you store the images, and how you serve them - either directly or via an image servlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!