wood burning stoves 2.0*
The moose likes Servlets and the fly likes Why request.getParts() returns empty in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why request.getParts() returns empty in servlet" Watch "Why request.getParts() returns empty in servlet" New topic
Author

Why request.getParts() returns empty in servlet

Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

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.


PM Me If You Want to get Urgent Help on Java Programming
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

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

without "name" attribute, it doesn't work with all Firefox, Chrome and IE.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Ulf is correct. Unnamed form elements do not participate in the submission.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why request.getParts() returns empty in servlet
 
Similar Threads
text field returns null on servlet with file - text field combination
FileUpload - Request empty with IE8
File Upload Problem with WAS 4.0.1
problem with multipart/form-data
request.getPart("name") in Tomcat 7