File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes image upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "image upload" Watch "image upload" New topic
Author

image upload

shalindra Singh Suryvanshee
Greenhorn

Joined: Aug 05, 2008
Posts: 25
I am working in a web application in witch I need to add the functionality to upload image for a perticular product and document if any to display them wherever is needed. I am using JBOSS and Struts.

I did it but wonder in following scenerios...

1. If I am giving relative path to upload it inside C:\jboss,(using classPath already set) but don't know how to display these images in a JSP(these are stored outside of context of an web application).

2. if I am using getServlet().getServletContext().getRealPath("/")+"images", to store the images, it is storing @ 'C:\jboss\server\default\tmp\deploy\tmp8651vinapp.ear-contents\vinweb-exp.war'. so as soon as Jboss restarted all images get lost.

Can you please suggest me what should be the proper way to upload and save (location) the image (preferably outside of ear) and also to display those images from that location over JSP.
due to certain restriction I can not save images i Database.

Please help me. Its urgent!
Thanks in advance.


Regards
Shalindra Singh
SCJP, SCWCD
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest keeping the files outside the web context. When you want to display them in a JSP, use an action to retrieve the file and download it to the user. On the JSP side, you can do something like this:


Merrill
Consultant, Sima Solutions
shalindra Singh Suryvanshee
Greenhorn

Joined: Aug 05, 2008
Posts: 25
Thanks for reply...
Can I have sample code for that action... I am not able to get properly, how should I do the needful..

Thanks
Shalindra
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you're using Struts 1.2.6 or above, you can make use of the DownloadAction class for this purpose. Here's an example:

Note that if you're using struts 1.3.x you must include the struts-extras-1.3.x.jar file in your WEB-INF/lib directory. The JSP entry for the above would be:

[ August 06, 2008: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image upload