• 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

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic