• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to implement file upload and download in struts2

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

i want to implement file upload and download functioality in my application using struts2. i tried to use the examples from showcase and it seems to be working but they are static and i m not able to find some good example. if any body has implemented this functionality please share with me or post some good example.

I have few specific question.

1. when i m uploading a file what should be the path to store so that it can be downloaded also. should it be under tomcat or anywhere it can be saved.

2. when i am downloading a file it seems it should be under tomcat/webapp/project. that means it should be saved here only. i m not sure how will it work.

If any body have done it please help. it is very urjent.

thanks in advance.

Sunil
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sunil,

To download file, the file should be present at the location where server is running because when any user will click on download button , the action present in server will be called and it will do whole processing .
I have done the same thing. In my application first of all i fetched the file from database and stored it in the location where tomcat server is running and then click of download button this this file will be downloaded.
Here is my code to save a file at server location :-

File file=new File("abc.jpg");
file.createNewFile();

this code will automatically create the file where server is running


hopefully this will help U.

 
Ranch Hand
Posts: 53
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sunil

I am using this code for file uploading.




You can find this code on the official web site of Struts 2 in action by manning publication.

and yes you have to save the file in tomcat itself, as per my knowledge.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
File uploading is handled by the framework; there's no need to read an input stream:

http://struts.apache.org/2.x/docs/file-upload.html

Uploaded files can be put anywhere.

Downloading files may be handled by the "stream" result:

http://struts.apache.org/2.0.14/docs/stream-result.html

or written directly to the response.
 
Bilal A. Siddiqui
Ranch Hand
Posts: 53
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks David.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic