I have been looking into the examples for uploading files using struts and tried many ways to make it work on RAD 6.0 dev environment (WebSphere 6). For some reason the type="file" form field is not getting posted to the Action. I am using working examples from other posters (thanks). Still cannot figure out why the file is being stripped out.
I have added new entries into my struts-config-ext.xml (Stores/WebContent/WEB-INF):
Here is the Action I defined: <action path="/FileUpload" type="com.nsp.utils.StrutsUploadAction" name="myForm" scope="request" validate="true" input="/NSP/nsp_nspfileupload.jsp"> <forward name="success" path="/NSP/nsp_nspfileupload.jsp"/> </action>
The Action I use is here. The issue as well. myFile comes as null all the time.
I vaguely remember seeing a strange problem similar to yours where the fact that the method="post" attribute was before the enctype attribute made a difference. I'd suggest you remove method="post" entirely since post is the default method for an <html:struts> tag.
Also, check the size of the file. If it's larger than the maxiumum file size specified in the <controller> element of your struts-config.xml file, Stuts will simply return null to the FormFile without any error message. [ April 10, 2008: Message edited by: Merrill Higginson ]
I implemented your suggestion. Removed the method="post". Tried again. Same result. myFile was null.
I do not have any <controller> section in my struts. I think is defaulted tp 250M. I will put the <controller> into struts-config-ext.xml tomorrow to see if that would make any difference.
I also verified that my struts-fileupload.jar is dated 2003. I think it is 1.0 version. I am not sure if there is an incompatibility issue. Also RAD (WebSphere Development env for 6) uses its own struts libraries. I am not aware of any issues there. I looked into the IBM developerworks postings as well.
I might be running out of options as I need to find a solution fast (isn't it always the case?).
Hehe, precisely! Anyways, your problem certainly seems to have that unique touch to it, which for a programmer can get very frustrating.
Since we're at it, how about setting validate="false" and removing the "input" attribute from your <action> mapping tag. Just a gut feeling I fear. Can't really vouch, but then we're low on alternatives already!
Here's one other suggestion: Try downloading Struts 1.1 again from the Struts home page. Then put the upload jar file from that download into your WEB-INF/lib folder and see if that makes a difference.
I implemented both suggestions (put the struts 1.1 into WC/lib and struts-config changes). Unfortunately it didn't work. I added a text field and checked them on debug session. elementsText is full from the CommonsMultipartRequestHandler shows. elementsFile has no entry!
Anything else you can think of? The code is exactly as it is in my original posting (with some suggestion changes in the postings). I just can't make this work.
One comment I found on struts and on some postings was that struts already parses the multipart form, hence removing the form all together might work. I will try and let you know as soon as I get a chance.
This will save the file! Remember that uploading is already handled out of the box is you are using commerce. Not sure if you use straight WebSphere it would cover that too. I would assume it maynot. The the regular struts methods should suffice.