We don't get a FormFile in struts 2, it's an actual File. But mine is junk.
Can someone send me the jsp, struts.xml, and action java code for a working
example of file upload.
I put up everything I had in this thread, and nobody found anything wrong with
it; at this point, I'll have to use someone else's (not the showcase, that
doesn't work).
Thanks,
> hi!! i dont know about struts 2, but i tried uploading images to the
> server using Struts 1.2,and it works just fine..i dont think we get the
> uploaded file as it is.. wat u said is true.. we get a temp file at
> different locations for each web container...basically watever files are
> uploaded, are obtained as objects of class FormFile. we have a method
> called FormFile.getInputStream()..i think the rest is understood..get the
> InputStream,name the o/p file appropriately using
> FormFile.getContentType() ,write to the o/p file . sorry that iam not
> able to give you the jsp code in the tags format that you wrote..i dont
> know it.if u have multiple files to handle, get them as a FormFile array,
> for each element,verify content type and call the method where the file
> saving logic is written
>
> here is the code
>
> in the jsp,
>
> <html:form action="/UploadAction.do?" method="post"
> enctype="multipart/form-data"> File 1 <html:file property="myFile1"/> <br>
> <html:submit>Upload Files</html:submit> </html:form>
> ------------------------------------------------------------------- in the
> form bean, public class UploadForm extends ActionForm{
>
> FormFile myFile1; public FormFile getMyFile1() { return myFile1; }
>
> public void setMyFile1(FormFile myFile1) { this.myFile1 = myFile1; } }
> -------------------------------------------------------------------------
> -- in the execute method of Action,
>
> UploadForm uForm = (UploadForm) form; FormFile f = uForm.getMyFile1();
> InputStream is = f.getInputStream(); FileOutputStream fout = new
> FileOutputStream("putSomePathHere"); int i=0; do{ i = is.read();
>
> if(i != -1) fout.write(i); } while(i != -1); is.close(); fout.close();
> f.destroy(); System.out.println("Temp File removed"); }
>
>
>
>
> abhiram
>
>
>
>
>
> --------------------------------- Get the freedom to save as many mails as
> you wish. Click here to know how.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]