File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Display images in JSP - files in folder other than project one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

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

Dan Arbo
Greenhorn

Joined: Jul 04, 2011
Posts: 22
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
Bartender

Joined: Oct 14, 2005
Posts: 18116
    
    8

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

Joined: Jul 04, 2011
Posts: 22
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

Joined: Jan 09, 2013
Posts: 2
Hi,
I am using Struts 1.2. How to do the same using struts actions and JSP. Please.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
xavier, This is a pretty old thread. Start afresh. What have you done so far?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display images in JSP - files in folder other than project one
 
Similar Threads
Deliver Static content
URL's to images
Displaying images dynamically from database
Changing <context-root>
Accessing images under WEB-INF