It's not a Struts bug, and it's not even a Struts-related problem. Any time
you need to upload files, you must use a POST request with an 'enctype' of
"multipart/form-data". Your form element should look like this:

<html:form action="/imageUpload.do" type="imageUploadForm"
enctype="multipart/form-data">

--
Martin Cooper


"Bryan Hunt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi there list,
> I have been trying to get the most simple file upload example working with
> and have been receiving a strange error message that I just can't seem
> to shake.
>
> Here is the basics of my action form
> snip=
> public class ImageUploadForm extends ActionForm {
>     // --------------------------------------------------------- 
> Instance Variables
>     /** imageFile property */
>     protected FormFile file;
>
>     // --------------------------------------------------------- Methods
>
>     public ActionErrors validate(
>         ActionMapping mapping,
>         HttpServletRequest request) {
>
>         if(file == null){
>             System.out.println("file is empty");
>         }
>     return null;
>     }
>
>     public FormFile getFile() {
>         return file;
>     }
>
>     public void setFile(FormFile file) {
>         this.file = file;
>     }
> =snip
>
> Here is the basics of the action
> snip=
> public ActionForward execute(
>       blah) {
>             System.out.println("at least i managed to get called");
>         throw new UnsupportedOperationException("Generated method
> 'execute(...)' not implemented.");
>     }
> =snip
>
> Here is the basics from my struts config file
> snip=
>     <form-bean name="imageUploadForm"
> type="ie.jestate.struts.form.ImageUploadForm">
>             <form-property name="file"
> type="org.apache.struts.upload.FormFile" />
>         </form-bean>
> <action
>             attribute="imageUploadForm"
>             input="/form/imageUpload.jsp"
>             name="imageUploadForm"
>             path="/imageUpload"
>             type="ie.jestate.struts.action.ImageUploadAction"
>             scope="request"
>             validate="true"
>             >
>             <forward name="imageuploadsuccess"
> path="/form/imageUpload.jsp" />
>         </action>
> =snip
>
> Here is the jsp file
>
> snip=
> <%@ page language="java"%>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean";
prefix="bean"%>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html";
prefix="html"%>
> <html>
>     <head>
>         <title>JSP for imageUploadForm form</title>
>     </head>
>     <body>
>         <html:form action="/imageUpload.do" type="imageUploadForm" >
>             File :
>               <html:file property="file"/>
>             <html:submit/>
>         </html:form>
>     <body>
>     </html>
> =snip
>
> And here is the abreviated version of the error message
> snip=
>
> *exception*
>
> javax.servlet.ServletException: BeanUtils.populate
> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
>
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.j
ava:821)*
>
> cause mère*
>
> java.lang.IllegalArgumentException: argument type mismatch
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> =snip
>
> I have tried changing the type to text and the type to String in
> the form and that works but use this FormFile class and everything
> seems to go fubar.
>
>
> It never even gets to call the action , instead it generates this error
> message ,
> but the setters and getters are right and the variable is public, this
> only happens
> with the FormFile. All the struts stuff is in my classpath as is
> commons-fileupload-1.0.jar.
>
> Anyone got any idea what the hell I'm doing wrong ... I'm starting to
> suspect this
> could be a struts bug cause everything looks straightforward enough.
>
> --B




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to