This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes FormFile not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "FormFile not working " Watch "FormFile not working " New topic

FormFile not working

bharathi Subramaniyan

Joined: Jun 02, 2010
Posts: 2
Hi all,

I am using Struts 1.1. In my application i wand to upload the file.So i used the FormFile interface in my FormBean class.
please check the below code.

public class DocumentUploadForm extends ActionForm {

private FormFile documentName;

public FormFile getDocumentName() {
return documentName;

public void setDocumentName(FormFile documentName) {
this.documentName = documentName;


public class DocumentUploadAction extends DispatchActionSupport{

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

System.out.println(_className+_actionName+"File Name = "+documentUploadForm.getDocumentName().getFileName());


<html:form action="DocumentUpload" name="docUploadForm"
type="" method="POST" enctype="multipart/form-data">

<html:file property="documentName"/>


<form-bean name="docUploadForm" type=""/>
<action path="/DocumentUpload"
<forward name="confirm" path="/docx/documentmaintenance/DocumentUploadConfirm.jsp"/>

If i run the application after entering the values in the page i cant go to the action class and i am not getting exceptions.
If i remove the FormFile and adding some other tag like html:text it navigating to the action class.

Kindly help me.

Bharathi S.
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249

For file upload to work correctly, the method=POST needs to be mentioned in the form definition as well as the correct path.
I'm not sure if that is the culprit, but you did miss the "slash" before the DocumentUpload in action="DocumentUpload"


<form type="blah-blah-blah" path="/some_path" method="post">
David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
David Newton

Joined: Sep 29, 2008
Posts: 12617

For file upload to work right it the form needs to be multipart encoded, not just a POST.
bharathi Subramaniyan

Joined: Jun 02, 2010
Posts: 2
This is because of the jar file missed to add in the classpath.
I agree. Here's the link:
subject: FormFile not working
Similar Threads
Map the action form object
Exception creating bean of class org.dhsinfo. content.AddFileForm: {1}'
File Upload using Struts
Displaying file content in a jsp page
FileUploading in struts