?
Solved

File Upload in Struts 2.0 example

Posted on 2011-05-10
21
Medium Priority
?
492 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:ajayvegesna02
  • 9
  • 9
19 Comments
 
LVL 23

Expert Comment

by:cmalakar
ID: 35731977
>>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
 

Author Comment

by:ajayvegesna02
ID: 35732005
How to get save the file without know full file Path.. can u pls explain little deeper
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35732028
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ajayvegesna02
ID: 35732050
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
 
LVL 23

Accepted Solution

by:
cmalakar earned 1000 total points
ID: 35732054
0
 

Author Comment

by:ajayvegesna02
ID: 35732174
thanks.... lmc
0
 

Author Comment

by:ajayvegesna02
ID: 35732310
heay.. i am saving it into fixed path.. how to get the project holder path??
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35734595
what do you mean by project holder path ?
0
 

Author Comment

by:ajayvegesna02
ID: 35735389
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35738031
0
 

Author Comment

by:ajayvegesna02
ID: 35739429
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35739702
What do you mean by opening the file ?
0
 

Author Comment

by:ajayvegesna02
ID: 35739749
when click on the link.. it should ask open or download... as like normal scenarios on web
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35739866
then basically you need download functionality.. Looks at this example

http://sheetalshundori.blogspot.com/2008/02/struts2-dynamic-file-download.html
0
 

Author Comment

by:ajayvegesna02
ID: 35739877
lmc... and will update u
0
 

Author Comment

by:ajayvegesna02
ID: 35862733
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35862734
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
 
LVL 23

Expert Comment

by:cmalakar
ID: 35868155
ajayvegesna02,

Please explain why my comments were not helpful.

0
 

Expert Comment

by:WhackAMod
ID: 35929432
Starting closing process on behalf of the asker.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question