Link to home
Start Free TrialLog in
Avatar of ajayvegesna02
ajayvegesna02

asked on

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
Avatar of cmalakar
cmalakar
Flag of India image

>>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.
Avatar of ajayvegesna02
ajayvegesna02

ASKER

How to get save the file without know full file Path.. can u pls explain little deeper
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.
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???
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks.... lmc
heay.. i am saving it into fixed path.. how to get the project holder path??
what do you mean by project holder path ?
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....
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
What do you mean by opening the file ?
when click on the link.. it should ask open or download... as like normal scenarios on web
then basically you need download functionality.. Looks at this example

http://sheetalshundori.blogspot.com/2008/02/struts2-dynamic-file-download.html
lmc... and will update u
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
Why ?

There were some comments with examples on how to achieve.

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

Please explain why my comments were not helpful.

Avatar of WhackAMod
Starting closing process on behalf of the asker.