Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing parameters with ENCTYPE=multipart/form-data

 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey vaibhav my email address programmer@netlimit.com
Thanks dude
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic