File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts upload not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts upload not working" Watch "Struts upload not working" New topic

Struts upload not working

Sree Jag
Ranch Hand

Joined: Oct 14, 2003
Posts: 77
Hi all,

I am trying to add File Upload functionality to my webapp using Struts <html:file>

This is my JSP code:

<html:form action="/" enctype="multipart/form-data" onsubmit="self.opener.location.reload(false);self.close();">

<html:file name="itemmaintenanceForm" property="theFile"/>
<html:image property="image" src="/Images/Admin/btnSave.gif" onclic="this.form.submit()"/>


but when i click on the Save image, the form is submitted without any data.

But it submits all the data if i remove the
enctype="multipart/form-data" from the html:form tag, the form is being submitted with all the data.

Can anyone tell me what's the problem?

Thanks in advance,

Sree Jag<br />SCJP 1.4
hrt prasad

Joined: Sep 02, 2004
Posts: 4
Try putting method="post" in the form tag.

also - "onclic" for image - Is this a spelling mistake?
Sree Jag
Ranch Hand

Joined: Oct 14, 2003
Posts: 77
hi hr, i tried with method="post" too with no luck. btw, onclic is not a typo...javaranch was not allowing me to post message with onclick.

any other ideas?
Sree Jag
Ranch Hand

Joined: Oct 14, 2003
Posts: 77
i found the problem.

the problem is not with <b>enctype="multipart/form-data"</b>. the problem is with the <b>onsubmit</b> function.

if i remove teh onsubmit function, then the upload file is working.

any ideas how to solve this problem

I agree. Here's the link:
subject: Struts upload not working
jQuery in Action, 3rd edition