Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Action called twice when form enctype is multipart/form-data

Reply
Thread Tools

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

 
 
Duncan
Guest
Posts: n/a
 
      02-24-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML File Upload using enctype=multipart/form-data in form? Matt Java 8 05-26-2012 07:40 AM
How to retrieve form field value if form is EncType=multipart/form-dataForm? Li Zhang ASP .Net 4 02-27-2009 01:23 AM
can enctype="Multipart/Form-Data" always be used on a form? Stimp ASP .Net 1 11-09-2006 12:48 PM
HTML File Upload using enctype=multipart/form-data in form? Matt HTML 1 10-12-2004 08:17 PM
Using <form ... enctype="multipart/form-data"> David Lozzi ASP General 5 08-12-2003 05:23 PM



Advertisments