You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bryan Hunt <ad...@revoltingdigits.com> on 2004/05/03 22:10:03 UTC

struts file upload strange error

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.java: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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts file upload strange error

Posted by Richard Yee <ry...@cruzio.com>.
darn! I knew I should have answered this one!
-R
>Dude, send me your address and I will fed-ex you a cold beer 
>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>I should have thought of that before. Thanks for your help !!!!!!!! I've 
>just wasted 24 hours
>on this.... If I was running linux I could have ran a packet capture but 
>am on crappy
>win 2000 box.
>
>--B
>
>
>Martin Cooper wrote:
>
>>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" <ad...@revoltingdigits.com> wrote in message
>>news:4096A71B.5040606@revoltingdigits.com...
>>
>>
>>>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>
>>>        <DEFANGED_html:form action="/imageUpload.do" 
>>> type="imageUploadForm" >
>>>            File :
>>>              <DEFANGED_html:file property="file"/>
>>>            <DEFANGED_html:submit/>
>>>        </DEFANGED_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: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org



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


Re: struts file upload strange error

Posted by Martin Cooper <ma...@apache.org>.
"John Moore" <jo...@jmsd.co.uk> wrote in message
news:6.0.1.1.0.20040504113321.042aa740@pop3.gotadsl.co.uk...
> At 01:13 04/05/2004, Bryan Hunt wrote:
>
> >Dude, send me your address and I will fed-ex you a cold beer
> >!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> >I should have thought of that before. Thanks for your help !!!!!!!! I've
> >just wasted 24 hours
> >on this.... If I was running linux I could have ran a packet capture but
> >am on crappy
> >win 2000 box.
>
> Get yourself a copy of Network Spy
> (http://sumitbirla.com/network-spy/netspy.php), which is a very useful
> packet capture tool for Windows.

On Windows 2000, you have Network Monitor built in, so you don't actually
need any additional software...

--
Martin Cooper


>
> John
>
>
>
>
>
> =============================================
> John Moore     -    Norwich, UK    -    john@jmsd.co.uk
> =============================================
>


----------------------------------------------------------------------------
----


>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.662 / Virus Database: 425 - Release Date: 20/04/2004
>
>


----------------------------------------------------------------------------
----


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




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


Re: struts file upload strange error

Posted by John Moore <jo...@jmsd.co.uk>.
At 01:13 04/05/2004, Bryan Hunt wrote:

>Dude, send me your address and I will fed-ex you a cold beer 
>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>I should have thought of that before. Thanks for your help !!!!!!!! I've 
>just wasted 24 hours
>on this.... If I was running linux I could have ran a packet capture but 
>am on crappy
>win 2000 box.

Get yourself a copy of Network Spy 
(http://sumitbirla.com/network-spy/netspy.php), which is a very useful 
packet capture tool for Windows.

John





=============================================
John Moore     -    Norwich, UK    -    john@jmsd.co.uk
=============================================  

Re: struts file upload strange error

Posted by Bryan Hunt <ad...@revoltingdigits.com>.
Dude, send me your address and I will fed-ex you a cold beer 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I should have thought of that before. Thanks for your help !!!!!!!! I've 
just wasted 24 hours
on this.... If I was running linux I could have ran a packet capture but 
am on crappy
win 2000 box.

--B


Martin Cooper wrote:

>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" <ad...@revoltingdigits.com> wrote in message
>news:4096A71B.5040606@revoltingdigits.com...
>  
>
>>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>
>>        <DEFANGED_html:form action="/imageUpload.do" type="imageUploadForm" >
>>            File :
>>              <DEFANGED_html:file property="file"/>
>>            <DEFANGED_html:submit/>
>>        </DEFANGED_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: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>


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


Re: struts file upload strange error

Posted by Martin Cooper <ma...@apache.org>.
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" <ad...@revoltingdigits.com> wrote in message
news:4096A71B.5040606@revoltingdigits.com...
> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org