Reputation: 173
I came across a problem that when I try to upload a file in Struts using <html:file/>
this is part of my jsp
<tr>
<td width="18%" bgcolor="#DEE3E7" align="center">
<bean:write name="replaceAttachmentsForm" property="destId"/>
</td>
<td>
Subject
</td>
<td width="18%" bgcolor="#DEE3E7" align="center">
<bean:write name="replaceAttachmentsForm" property="concernedDept"/>
</td>
<td width="18%" bgcolor="#DEE3E7" align="center">
<bean:write name="replaceAttachmentsForm" property="letterSubject"/>
</td>
<td width="18%" bgcolor="#DEE3E7" align="center">
<html:file property="formFileLetter" name="replaceAttachmentsForm" ></html:file>
</td>
</tr>
And this is the registered bean
public class ReplaceAttachmentsForm extends WebActionForm{
private FormFile formFileLetter;
private FormFile formFileAttachment;
public void setFormFileLetter(FormFile formFileLetter) {
this.formFileLetter = formFileLetter;
}
public FormFile getFormFileLetter() {
return formFileLetter;
}
public void setFormFileAttachment(FormFile formFileAttachment) {
this.formFileAttachment = formFileAttachment;
}
public FormFile getFormFileAttachment() {
return formFileAttachment;
}}
The problem here is that whenever I try to upload a file an exception
"Cannot invoke ae.ems.let.web.ReplaceAttachmentsForm.setFormFileLetter on bean class 'class ae.ems.let.web.ReplaceAttachmentsForm' - type mismatch - had objects of type "java.lang.String" but expected signature "org.apache.struts.upload.FormFile"
Can anyone suggest Why am I not able to upload a file using Struts tags? Any help in this regard is highly appreciated.
Upvotes: 0
Views: 541
Reputation: 173
So after a bit of digging, it turns out that I missed enctype="multipart/form-data"
attribute of the <html:form/>
Upvotes: 1