File Upload in Struts 2.0 example

Hi,

I am using the File Upload tag of struts 2.0....

<s:file name="filePath" label="Upload Course File" value="filePath" />

filePath is the vaiable in action class .. whenever i upload the file.. then i am accessing the filePath in respective action classs.. but i am getting the fileName of the pdf(which i have uploaded)... how to get the full path of the file and how to save it....

My requirement is to save the file in some holder and need to display in display tag and the title should be "View file" , when the user clicks on the "view File".. the uploaded file should be opened.. how can i achieve this.

Thanks,
Ajay
ajayvegesna02Asked:
Who is Participating?
 
cmalakarCommented:
>>how to get the full path of the file and how to save it

You will not get the full path of file being uploaded. You can save it to any location you want on server, and when user clicks the view file, that file should be downloaded at client side.
0
 
ajayvegesna02Author Commented:
How to get save the file without know full file Path.. can u pls explain little deeper
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
cmalakarCommented:
That should be application specific.

Users can upload the file from any other machine. In that case, you may not  have exact path on server or the same drive may not present.
Any file uploaded, you should store it in some common location on your server.
0
 
ajayvegesna02Author Commented:
yes.. i know that.. but my question is how to save it in server by using the filePath variable .. i am new to struts.. can you give me the sample code???
0
 
ajayvegesna02Author Commented:
thanks.... lmc
0
 
ajayvegesna02Author Commented:
heay.. i am saving it into fixed path.. how to get the project holder path??
0
 
cmalakarCommented:
what do you mean by project holder path ?
0
 
ajayvegesna02Author Commented:
suppose i have my project in D:\SomeFolder...
how to get this path in coding because it will be stored some other drive in future....
0
 
cmalakarCommented:
0
 
ajayvegesna02Author Commented:
thanks....

only the final Requirement  is pending

I have display table with no.of rows .. in that i have some columns , the last column contains the "View File" .. i am getting the file path from the db.. now when the user clicks on the "View File", i have to open the file based  on the file path.. how to get this...

Thanks,
Ajay Varma
0
 
cmalakarCommented:
What do you mean by opening the file ?
0
 
ajayvegesna02Author Commented:
when click on the link.. it should ask open or download... as like normal scenarios on web
0
 
cmalakarCommented:
then basically you need download functionality.. Looks at this example

http://sheetalshundori.blogspot.com/2008/02/struts2-dynamic-file-download.html
0
 
ajayvegesna02Author Commented:
lmc... and will update u
0
 
ajayvegesna02Author Commented:
I've requested that this question be deleted for the following reason:

got the solution.Now able to download and view the files in struts 2.0
0
 
cmalakarCommented:
Why ?

There were some comments with examples on how to achieve.

Nothing was useful ? If so, Can you please post what you have done ?
0
 
cmalakarCommented:
ajayvegesna02,

Please explain why my comments were not helpful.

0
 
WhackAModCommented:
Starting closing process on behalf of the asker.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.