File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes File Upload using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "File Upload using Struts" Watch "File Upload using Struts" New topic
Author

File Upload using Struts

Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Has anyone attempted file upload using Struts?
I am able to upload a file but then the automatic loading of form bean data is disrupted. Can anyone show me how to accomplish both
Regards
SR


Commentary From the Sidelines of history
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
Take a look at the examples that come with the Struts download. One of them shows how to upload files using Struts.
Darryl
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Thank you Darryl, I wish I had looked into those examples earlier.
Regards
SR
Mary White
Ranch Hand

Joined: Jan 27, 2003
Posts: 41
In what sample did you find the upload usage?
How do you retreive the BLOB once it's in the database?
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi Mary,
It seems to me you are experiencing another problem altogether. The Struts upload example shows how to use its file upload classes to upload a file to the file system. It does not indicate how to store and retrieve files as BLOBs in a database.
I won't be of much use for the latter question as I've never designed a database for use as a file repository :-) Sorry about that.
Darryl
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
You should be able to find the upload samples in the jakarta-struts-1.0.2-src package, buried somewhere under the src/upload directory.
HTH.
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
I got an email from a fellow rancher requesting me to provide sample code related to file upload in Struts. I was able to successfully implement the file upload functionality in production and here is the code require to do so..

JSP Code:
This code sets up the html form for upload requests. Note the form tag with the encoding type set to multipart-form data. Use the html:file tag for the text box that will be used to specify the file that needs to be uploaded. This will automatically provide a "Browse" button.



In your ActionForm class:
The following lines are important


In the action class that will process the uploaded file:


In the CSV Utility file:


You can find ExcelCSVParser at Ostermiller.org

Hope this helps..
sai kinnera
Ranch Hand

Joined: Aug 12, 2004
Posts: 52
Can we customize the 'Browse' button that comes along with struts file upload.i.e., if we want to keep a customized image("Browse"), how could we accomplish it.
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
I built a Struts application that demonstrates file upload and file download.

The code is on SourceForge: http://strutsblobapp.sourceforge.net/
JothiKumar Ekanath
Ranch Hand

Joined: Dec 21, 2003
Posts: 30
Originally posted by sai kinnera:
Can we customize the 'Browse' button that comes along with struts file upload.i.e., if we want to keep a customized image("Browse"), how could we accomplish it.



Hi Sai kinnera
Did u able to find the answer for you question,If yes please let us know the answer.If no,Ranchers please help us.

Thanks
JK
Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
What exactly the commons-fileupload package do??

Can anyone provide me tutorial or more information abt it???

Grishma
Joel Espinosa
Greenhorn

Joined: Sep 09, 2005
Posts: 2
I know how to upload and download a file stored in the server with struts, what i don't know is how to update these file, how i can reuse my ActionForm in order to make and update of the file. In my app the file is saved in postgres.

Kind regards.


JAEC
blogmetroblog
ganesh vadivel
Greenhorn

Joined: Jun 24, 2006
Posts: 1
hi Paul McKenna and others,

this is ganesh ,i implement ur code for uploading the file in struts,
the flow is going fine,but the file is not uploaded any where.
I also implented controller ,code i specified below,
still the file is not getting uploaded any where.

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" tempDir="/testfolder1/" />

let me know ,how to proceed...

If any other can able to solve my problem,plz.

thanks in advance,
ganesh

[ June 24, 2006: Message edited by: ganesh vadivel ]
[ June 24, 2006: Message edited by: ganesh vadivel ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
While the code in the above posts shows something about how to read an uploaded file, none of the posts show code to save the file on the server. If you are unfamiliar with how to write a file, This link should help.
[ June 25, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Upload using Struts