Hello This is the 3rd time i am bringing out this problem hope i get a answer this time. I am using a file upload servlet to upload a file from a jsp page .The form in the jsp page needs to be of the encode type "multipart/form-data". What i want to do is to collect other info abt the file like Author ,Description and put it into the database but as soon as i use request.getParameter() in the servlet i am gettin null values Can any 1 suggest a way out Maha Anna pls HElp Amit [This message has been edited by Amit Roy (edited April 15, 2001).]
Servlets do not support multipart/form-data directly, that is, the request object does not parse the form parameters. However, all the information you need is in the request input stream. There's a little bit of work involved, but you can figure out what to do by working with this test servlet:
Now use this servlet as the target of your upload: <form method="POST" action="the servlet" enctype="multipart/form-data"> ... </form> Look at the results. You'll note that each field in your form appears in its own section (that's why it's called multipart). The sections are delimited by a boundary string that is passed in the "boundary" attribute of the content type. Each section has its own HTTP headers, including at least "Content-Disposition", which gives you the field name. After all the headers in a section comes a blank line, followed by the actual data, either the file upload data or the form value. ------------------ Phil Hanna Author of : JSP: The Complete Reference Instant Java Servlets
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Hi, Amit I have the bunch of classes for multipart-form/data type and uploading files code.It is given in Oreilly's servlet book.But it needs some modifications that can be downloaded from oreilly's site.If you please give me your mail id I can attach that zip file.It has 6-7 classes which are inter-related. Please do not panic and abuse this forum for not getting the help.I ve also posted the query on defining custom tags in Tomcat.The reply is still awaited. Sometimes it happens that we post very specific queries the topic of which is rarely used by anybody else.Same is the case with mutipart-form/data that is hardly used.So please believe in this forum.Let me know your mail id.I ll send you the code which is too big.
Hi, Amit, I ve mailed you the classes on your given account in a zip file.Let me know if there is any problem even after using these classes.
Joined: Oct 10, 2000
Thanks Phil I tried out ur suggestion ,yes the request inputstream does contain all the info i require but i cant figure out as to how exactly i can extract the data i require from the entire String can you please be a bit more descriptive Sorry 4 the trouble Amit
Hi Amit, As Phil has suggested, you would need to use, the streams methods like readLine(), to get the contents from the stream. Since you would be aware of the content or the format in which the stream is populated, you could extract it in the same order. Assuming that your stream contains a String, boolean, char and a byte, in that order, the following code shows how to extract the contents.
Note that you have to extract the contents of the stream in the same order in which it is populated. Hope this helps, Regards, Sandeep Desai email@example.com
Sun Certified Java ProgrammerScored 93 per cent
Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
IBM Enterprise Connectivity with J2EE Scored 72 per cent
Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
[This message has been edited by Desai Sandeep (edited April 20, 2001).]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Passing parameters with ENCTYPE=multipart/form-data