aspose file tools*
The moose likes Struts and the fly likes html:form enctype= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:form enctype="multipart/form-data"" Watch "html:form enctype="multipart/form-data"" New topic
Author

html:form enctype="multipart/form-data"

Sam Mites
Greenhorn

Joined: Nov 27, 2005
Posts: 15
I am using <html:form>in my jsp where i am using attribute enctype="multipart/form-data" coz i gotta upload a file. along with that i also have a text field in the same html form. So because of the enctype tag, the text field is also getting encrypted and my actionform is not getting populated with the text field value and hence my action class is not performing the desired operation. How to handle this problem when my html form is having both "file" and "text" fields.


regards..

[ EJFH: See this. ]

[ December 05, 2005: Message edited by: Ernest Friedman-Hill ]

[ December 05, 2005: Message edited by: Sam Mites ]
[ December 05, 2005: Message edited by: Sam Mites ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I have forms that use both upload files and other input fields that work fine, so I know it can be done. I'd suggest that you study carefully the upload example that comes with the Struts download. It has an input field as well as a file upload field.


Merrill
Consultant, Sima Solutions
Sam Mites
Greenhorn

Joined: Nov 27, 2005
Posts: 15
Hi Merrill,
I studied it, and doing the same thing.but still I am getting the same problem.Can u supply me with some sample code.

thanks and regards
Sam Mites
Greenhorn

Joined: Nov 27, 2005
Posts: 15
Hi Merrill,

Thank u very much for the files. I went theough them. I still cant able to find the flaw in my code..

here are my sample code...the jsp

<html:form action="/protect/xccManageSolutionComponentsAdd.wss" method="post" enctype="multipart/form-data">
<!--here i am uploading the files-->
<table>
<tr>
<td width="30%">Add CFReport:</td>
<td width="30%" colspan="3"><html:file property="cfReport" size="50" /></td>
<td> </td>
</tr>
<tr>
<td width="25%">Add SEO csv file:</td>
<td width="30%" colspan="3"><html:file property="seoCsvFile" size="50" /></td>
</tr>
<!--here are my text fields -->
<tr>
<table>
<tr>
<td> Type : <html:text property="mesType" size="8" />  </td>
<td> Model :<html:text property="mesModel" size="8" />  </td>
<td> Feature/RPQ : <html:text property="mesFeature" size="12" /></td>
</tr>
</table>
</tr>
<tr>
<td align="right" colspan="5"><span class="button-gray">
<html:submit value="Add" /> </span></td>
</tr>
</table>
</html:form>

here is my form bean

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class XCCManageSolutionComponentsForm extends ActionForm
{
private FormFile cfReport;
private String mesFeature;
private String mesModel;
private String mesType;
private FormFile seoCsvFile;
public FormFile getCfReport()
{
return cfReport;
}
public String getMesFeature()
{
return mesFeature;
}
public String getMesModel()
{
return mesModel;
}
public String getMesType()
{
return mesType;
}
public String getSearchSeo()
{
return searchSeo;
}
public FormFile getSeoCsvFile()
{
return seoCsvFile;
}
public void setCfReport(FormFile cfReport)
{
this.cfReport = cfReport;
}
public void setMesFeature(String mesFeature)
{
this.mesFeature = mesFeature;
}
public void setMesModel(String mesModel)
{
this.mesModel = mesModel;
}
public void setMesType(String mesType)
{
this.mesType = mesType;
}
public void setSeoCsvFile(FormFile seoCsvFile)
{
this.seoCsvFile = seoCsvFile;
}

}

does the jsp and the form bean need change..???

thanks and regards
Sam Mites
Greenhorn

Joined: Nov 27, 2005
Posts: 15
plz refer to the above code...

When i run the server in the debug mode...in case of enctype="multipart/form-data" the form bean is not getting called. the control was directly going to the action class. Henct the form bean data were not populated and i am not able to access the data.

What may be the reason behind the action form not getting called??

when i am running this code without enctype="multipart/form-data" then every thing is ok and the form bean was called before the control goes to the acton class!!!

Thanks and regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:form enctype="multipart/form-data"