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
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
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.
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks.... lmc
ASKER
heay.. i am saving it into fixed path.. how to get the project holder path??
what do you mean by project holder path ?
ASKER
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....
how to get this path in coding because it will be stored some other drive in future....
You have to use http://download.oracle.com/javaee/1.3/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
to get the real path or absolute path.
to get the real path or absolute path.
ASKER
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
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 ?
ASKER
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
http://sheetalshundori.blogspot.com/2008/02/struts2-dynamic-file-download.html
ASKER
lmc... and will update u
ASKER
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
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 ?
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.
Please explain why my comments were not helpful.
Starting closing process on behalf of the asker.
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.