• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FormFile not working

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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="com.crimsonlogic.txc.trade.docx.ui.document.DocumentUploadForm" method="POST" enctype="multipart/form-data">

<html:file property="documentName"/>


</html:form>



<form-bean name="docUploadForm" type="com.crimsonlogic.txc.trade.docx.ui.document.DocumentUploadForm"/>
<action path="/DocumentUpload"
type="com.crimsonlogic.txc.trade.docx.ui.document.DocumentUploadAction"
name="docUploadForm"
scope="session">
<forward name="confirm" path="/docx/documentmaintenance/DocumentUploadConfirm.jsp"/>
</action>


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.


Regards,
Bharathi S.
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bharati..

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"

ie

<form type="blah-blah-blah" path="/some_path" method="post">
.
..
</form>
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For file upload to work right it the form needs to be multipart encoded, not just a POST.
 
bharathi Subramaniyan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is because of the jar file missed to add in the classpath.

commons-fileupload.jar

 
reply
    Bookmark Topic Watch Topic
  • New Topic