aspose file tools*
The moose likes JSP and the fly likes Classic File Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Classic File Upload" Watch "Classic File Upload" New topic
Author

Classic File Upload

Brian Percival
Ranch Hand

Joined: Jun 23, 2004
Posts: 163
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

Joined: Jan 10, 2002
Posts: 61769
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Percival
Ranch Hand

Joined: Jun 23, 2004
Posts: 163
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

Joined: Jan 10, 2002
Posts: 61769
    
  67

Yes, but once your servlet gains control, you must use the API of your upload package to interact with the request.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Brian Percival
Ranch Hand

Joined: Jun 23, 2004
Posts: 163
Ben, thanks alot for the explanation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classic File Upload