Action called twice when form enctype is multipart/form-data

Discussion in 'Java' started by Duncan, Feb 24, 2006.

  1. Duncan

    Duncan Guest

    Hi


    I have the following Struts Action


    public class HandleImageAction extends Action{

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {


    DynaActionForm theForm = (DynaActionForm)form;

    FormFile f = (FormFile)theForm.get("image");

    if(null == f){
    System.out.println("the file is null");
    }
    else{
    System.out.println("the file has " + f.getFileSize() + " bytes available");
    }

    return mapping.findForward("whatever");
    }
    }


    struts config is


    <form-bean name="imageForm" type="org.apache.struts.action.DynaActionForm">
    <form-property name="image" type="org.apache.struts.upload.FormFile"/>
    </form-bean>

    <action path="/handleimage" type="com.foo.images.HandleImageAction" name="imageForm"
    scope="session">
    <forward ...
    </action>

    here is my form

    <form name="imageform" action="handleimage.do" method="post" enctype="multipart/form-data">

    with the file field

    <input type="file" name="image">

    every time I submit this form the action is called twice.

    The first time I get 'the file is null' printed to the console
    The second time I get 'the file has 4090771 bytes available' which seems reasonable as this is the
    size of the file.

    I have read through my (useless) Struts book but it has one line about multipart requests.

    I'm sure my other (non multipart) Actions don't execute twice

    Anyone know why this is happening ?

    Many thanks

    Duncan
     
    Duncan, Feb 24, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    8
    Views:
    144,587
    zeeshanakhter2009
    May 26, 2012
  2. Matt
    Replies:
    1
    Views:
    11,294
    David Dorward
    Oct 12, 2004
  3. Stimp
    Replies:
    1
    Views:
    927
    Karl Seguin [MVP]
    Nov 9, 2006
  4. David Lozzi

    Using <form ... enctype="multipart/form-data">

    David Lozzi, Aug 12, 2003, in forum: ASP General
    Replies:
    5
    Views:
    362
    Martin CLAVREUIL
    Aug 12, 2003
  5. Kevin DeValck
    Replies:
    1
    Views:
    779
    7stud --
    May 17, 2011
Loading...

Share This Page