File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classic File Upload

 
Brian Percival
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on my form page, when I exclude enctype="multipart/form-data", I am able to read the parameters fine. but when I put it back.. I get error page (not any java error anyway, just IE error page). Below is the doPost:



Getting totally frustrated.. I see no sort of error anywhere but just nothign happens except for the IE error page. Please help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request.getParameter() method (and related methods) will ony work when the form is encoded as a "normal" submission. It will not parse the request to obtain the parameters when you submit a multi-part form.

That's why 3rd party file upload packages are so popular (see FAQ). They handle parsing the request for the file upload and make the request params available through their API.
[ September 12, 2007: Message edited by: Bear Bibeault ]
 
Brian Percival
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

I did read it, but I never thought the normal (non file) paramters will be disabled too.. atleast will the doGet/doPost methods will work right???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but once your servlet gains control, you must use the API of your upload package to interact with the request.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets delay reading the body of a post until you call either the getServletInputStream method or one of getParameter, getParameterMap, getParameterName, or getParameterValues. Once it goes down one of those two paths, it can't back up and go down the other.

This makes sense when you think about it because all the methods in the second group would require a parsing of the entire stream to work. Since a file upload can be megabytes or gigabytes long, reading the whole thing and holding it in memory, isn't feasible.
 
Brian Percival
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben, thanks alot for the explanation
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic