aspose file tools*
The moose likes Servlets and the fly likes Passing parameters with ENCTYPE=multipart/form-data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing parameters with ENCTYPE=multipart/form-data" Watch "Passing parameters with ENCTYPE=multipart/form-data" New topic
Author

Passing parameters with ENCTYPE=multipart/form-data

Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
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).]


<I>Chance Favours the Prepared minds"</I>
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
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>
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
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.


VAIBHAV <BR>SCJP
Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
hey vaibhav my email address programmer@netlimit.com
Thanks dude
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
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.
Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
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
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
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
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 20, 2001).]


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing parameters with ENCTYPE=multipart/form-data