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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 : file upload" Watch "Struts 2 : file upload" New topic

Struts 2 : file upload

kajal mukergi
Ranch Hand

Joined: Mar 22, 2007
Posts: 102
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,

David Newton

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 22, 2007
Posts: 102
Thanks David,

The links are very informative.

I agree. Here's the link:
subject: Struts 2 : file upload
It's not a secret anymore!