Solved

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

Posted on 2004-08-12
8
14,703 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Here's how to start interacting with our community through Post.
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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