• Post Reply Bookmark Topic Watch Topic
  • New Topic

Struts 2 : file upload  RSS feed

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

i am using tomcat server and strut 2 application

my problem is

when i am uploading the file using



then in action class

i am having getters and setters

like this



i am getting the values of all above

like file object with path like c://tomcat//work//catelina//....//xyz.tmp

and content = text / ...

and fileName = sss.txt (actual file name)

now problem is

I need to pass this file object to next action that is

From this action i have to go to other jsp ( collect some text )and then i have to go to the next action and submit these values to db.

1. so i have tried to save the same path c://tomcat//work//catelina//....//xyz.tmpand tried to send to other action & create new file object , but observed that when the first action get completes the "c://tomcat//work//catelina//....//xyz.tmp" gets deleted


CAN any one tell me how to handle this....

1. how can i get actual path of the file (c://xfolder//yfolder//sss.txt)
2. or is there any way to save the .tmp file till i complete my operations in action that is inserting values in DB.
3. or any way i can pass the file object created in one action to other action through JSP.
4. if i have to save this file into new location then where we have to save (in the tomcat...).

or any better solution please tell me

Thanks friends,

 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The upload interceptor deletes the file after the action is completed. If you need it copied somewhere else, just copy it.

You could use a dynamic result (see here and here for details) to pass the filename to another action, but that shouldn't be necessary--whatever logic is handling the file should be abstracted out of individual actions into a service-like object that can be used anywhere.
 
kajal mukergi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David,

The links are very informative.

Thanks
Kajal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!