File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image upload

 
shalindra Singh Suryvanshee
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
shalindra Singh Suryvanshee
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic