• 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

Why request.getParts() returns empty in servlet

 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I am stuck at a very strange behavior: I am writing a servlet for handling file upload, using @MultipartConfig annotation for the servlet. I inspected that this statement:



always returns an empty collection, even I had pick up a file in the upload form. Also the form declares enctype="multipart/form-data" already.

It's strange because I worked before but suddenly it doesn't work anymore today.

My environment is Win7-64-bit, Tomcat 7-64bit, Java 7-64bit.

Any suggestions are greatly welcome.

Thanks.
 
Nam Ha Minh
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I found where is the problem. I change code from:



to



I don't know why the attribute "name" matters here. Anyway, that could help if someone experiences the same problem like me.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think -not quite sure- that elements without a name attribute are not sent as part of the form submission. or maybe that's browser-dependent behavior.
 
Nam Ha Minh
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:... maybe that's browser-dependent behavior.


without "name" attribute, it doesn't work with all Firefox, Chrome and IE.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf is correct. Unnamed form elements do not participate in the submission.
 
reply
    Bookmark Topic Watch Topic
  • New Topic