struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Suresh Addagalla" <suresh.addaga...@wipro.com>
Subject RE: Uploading a file to server using struts
Date Wed, 30 Jul 2003 12:11:48 GMT

You can use this code in your Action class after declaring a form
element of type FormFile.

            FormFile file = (FormFile) theForm.get("theFile") ;

            String fileName = file.getFileName() ;
            int fileSize = file.getFileSize() ;

            if ( (fileName != null) && (!fileName.equals("")) ) {

                try {

                    if (fileSize != 0) {

                        File xmlFile = new File(uploadAreaTemp +
                                                File.separator +
                                                fileName) ;

                        FileOutputStream fos ;
                        fos = new FileOutputStream(xmlFile) ;
                        byte[] fileData = file.getFileData() ;
                        fos.write(fileData) ;
                        fos.close() ;

                } catch (Exception e) {}

> -----Original Message-----
> From: bhanu sistla [mailto:sistla_prakash@yahoo.co.uk] 
> Sent: Wednesday, July 30, 2003 5:41 PM
> To: struts-user@jakarta.apache.org
> Subject: Uploading a file to server using struts
> 
> 
> Hi All,
>  
> I have an urgent requirement. Has any body have the code how 
> to upload a file to server using struts frame work.
>  
> Regards
> Bhanu
> 
> 
> ---------------------------------
> Want to chat instantly with your online friends? Get the FREE 
> Yahoo!Messenger
> 


**************************Disclaimer************************************

Information contained in this E-MAIL being proprietary to Wipro Limited is 
'privileged' and 'confidential' and intended for use only by the individual
 or entity to which it is addressed. You are notified that any use, copying 
or dissemination of the information contained in the E-MAIL in any manner 
whatsoever is strictly prohibited.

***************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message