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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:form enctype="multipart/form-data" action=..." fails to submit form parameters" Watch "html:form enctype="multipart/form-data" action=..." fails to submit form parameters" New topic
Author

html:form enctype="multipart/form-data" action=..." fails to submit form parameters

Anita Ganga
Greenhorn

Joined: Oct 20, 2004
Posts: 28
I am trying to use <html:form> and I need to set the enctype="multipart/form-data".

I have a simple <html:submit>submit</html:submit> and a <html:hidden property="command" value="submit"/>field.

On submit it goes to right action but when i try to get the value of the hidden field it is null either through request or through the action form.

It works fine if i remove the attribute enctype="multipart/form-data" from the tag though.

Appreciate any thoughts why this is happening.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You should only use enctype="multipart/form-data" if you're uploading a file. If you're not uploading a file, remove this part of the <html:form> tag. If you are uploading a file, use <html:file> and make a property of type FormFile with the corresponding attribute name on your ActionForm. Then everything should work properly.
[ October 23, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Anita Ganga
Greenhorn

Joined: Oct 20, 2004
Posts: 28
Merrill,
thanks for the fast response

I need to upload a file in my struts form. I tried this already. I have an Actionform where I defined a variable of type formfile that corresponds to <html:file > property.
I have a html:submit and a hidden field whose value I am trying to get in the Actions execute.It always returns null

but no luck.. Apprecaite any more thougts
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
I believe the value attribute in hidden element is bean to be used not the actual value you want to submit. To make things easier to debug, initialize your hidden attribute to "submit" in action form's reset() method and test it.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In this thread you will find a good explanation by Travis Hein about what's actually happening internally when you specify enctype="multipart/form-data". After reading this, you'll understand why you can't get the parameter directly from the request. However, you should be able to get it from the ActionForm's getter method for the property. Are you 100% sure that this always yeilds null?
Anita Ganga
Greenhorn

Joined: Oct 20, 2004
Posts: 28
Merrill,
thanks for pointing me to this thread. that gives me a good insight..
But my case is really weird I am not able to get the values even through the form.
I am 100% sure it is returning null. It behaves as if it is not at all binding the html form values to the action form .

I checkes my Struts Config everything looks good there.

Does the scope of the form matter. In my case it is "request".
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
I was completely wrong on my earlier post. Anyway, Instead of guessing what's wrong why don't you dump the Servlet's inputstream to verify the content. If you have a filter you can write small snippet to retrieve the inputstream and dump the content (Remember this has to be done before control is passed to actionservlet). If hidden param is part of request you can confirm that.

Or you can think about some proxy stuff to view the request made from the client.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:form enctype="multipart/form-data" action=..." fails to submit form parameters