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

D

Duncan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top