Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
    Bookmark Topic Watch Topic
  • New Topic

Display images in JSP - files in folder other than project one

 
Dan Arbo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all,

I would like to allow users to upload images on to the server and then show them in a page. This is the approach I thought of, please also let me know if you think it makes sense at all:

- The web app resides in /home/me/app/WebContent
- The images are uploaded to /home/me/images_folder.

It is outside the web app folder, so that everytime I deploy a new version I do not delete them when replacing it with the new .WAR
But, since it is not inside it, I can't refer to it just using <img src = '/image.jpg'>

So I assume I have to create an output stream in a servlet and then pass it to the jsp.

Now, what I would like to do, if possible, is to still use the IMG tag so that I can style it with its CSS.
For example <IMG SRC = "FileOutputStream" class = "imgStyle">

Any suggestions?

Thanks in advance



 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dan Arbo wrote:It is outside the web app folder, so that everytime I deploy a new version I do not delete them when replacing it with the new .WAR
But, since it is not inside it, I can't refer to it just using <img src = '/image.jpg'>

So I assume I have to create an output stream in a servlet and then pass it to the jsp.

Yes, that's correct.
Now, what I would like to do, if possible, is to still use the IMG tag so that I can style it with its CSS.
For example <IMG SRC = "FileOutputStream" class = "imgStyle">


Yes, do that. Just make sure the URL you use refers to the servlet which serves the image.
 
Dan Arbo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
Paul, thanks for such a quick reply!

Also, not sure I accidentally deleted other people's post by mistake, if it's possible at all?
Think I saw a couple of replies but can't see them anymore. If I did, please accept my apologies.

Anyway, the solution:

In my JSP:



in my ImageTransfer servlet:



That did the trick.
 
xavier sundar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I am using Struts 1.2. How to do the same using struts actions and JSP. Please.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Report post to moderator
xavier, This is a pretty old thread. Start afresh. What have you done so far?
 
    Bookmark Topic Watch Topic
  • New Topic