Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Upload using Struts

 
Paul McKenna
Ugly Redneck
Ranch Hand
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Darryl, I wish I had looked into those examples earlier.
Regards
SR
 
Mary White
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly the commons-fileupload package do??

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

Grishma
 
Joel Espinosa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ganesh vadivel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic