Solved

Uploading a File with enctype=multipart/form-data and com.oreilly.servlet

Posted on 2004-08-12
8
14,691 Views
Last Modified: 2011-08-18
I had a JSP with a form that DID use "method=POST" and DID NOT use "enctype=multipart/form-data" and itworked beautifully. - Now I need to upload a file in the same form.
I figured out how to use com.oreilly.servlet in a simple form that DID use "enctype=multipart/form-data"
But now I have tried to combine the two forms.
When I add "enctype=multipart/form-data" to the original form, all of my fields are null.

1.) I need to use "method=post" because there is too much data to include in a URL for the get method
2.) Someone said that with "enctype=multipart/form-data" that JSP/servlets do not support the use of .getParameter() or that I need to "decode the request to get at the parameters and contents" of the form
3.) I would really like to use the com.oreilly.servlet package since I already got it to work and it is so simple.

So how can I pull all of the form data out of the form using POST and "enctype=multipart/form-data"?

Thanks in Advance,
MD
0
Comment
Question by:mderbin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:mderbin
ID: 11788681
Mr. Objects suggests that oReilly has an "implementation":
Comment from objects
this includes an implementation:
http://www.servlets.com/cos/index.html 

Does this mean that the oReilly package has a way of decoding the multipart POST?
I like oReilly.servlet, but there's not a lot of documentation to go along with it.

How can I use it to decode the form components?
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11790017
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11791688
why don't u use jakarta's upload component??

it is much easier than oreilly component
http://jakarta.apache.org/commons/fileupload/
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 11797989
what problems exactly are you having with oreilly?
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 11798036
0
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11798951
If you use struts and ActionForms, then programming will be easier and help will be widely available. You will also not get into problems which are trivial but waste lot of time :)
0
 
LVL 92

Expert Comment

by:objects
ID: 11805953
0
 

Expert Comment

by:dharmanands
ID: 12419600
There are also other solutions which might be helpful in general. I have also listed the advantages of each.

Problem: javax.servlet.HttpServletRequest.getParameter(String) returns null when the ContentType is multipart/form-data

Solutions:

Solution A: (Advantage: Free Distribution & Widely used)

1. Download one of the versions of UploadFile from http://jakarta.apache.org/commo
ns/fileupload/
2. Invoke parseRequest(request) on org.apache.commons.fileupload.FileUploadB
ase which returns list of org.apache.commons.fileupload.FileItem objects.
3. Invoke isFormField() on each of the FileItem objects. This determines whe
ther the file item is a form paramater or stream of uploaded file.
4. Invoke getFieldName() to get parameter name and getString() to get parame
ter value on FileItem if it's a form parameter. Invoke write(java.io.File) o
n FileItem to save the uploaded file stream to a file if the FileItem is not
 a form parameter.

Solution B (Advantage: Easy to use)

1. Download http://www.servlets.com/cos/index.html
2. Invoke getParameters() on com.oreilly.servlet.MultipartRequest

Solution C:

1. Download http://users.boone.net/wbrameld/multipartformdata/
2. Invoke getParameter on
com.bigfoot.bugar.servlet.http.MultipartFormData

Solution D (Restricted to those appliaction that use this framework):

Use Struts. Struts 1.1 handles this automatically.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question