Solved

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

Posted on 2004-08-12
8
14,670 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to access elements of included jsp  from parent jsp's save button 9 26
J2SE 5.0 metadata 1 61
using if condition without JSTL 2 112
lessBy10  challenge 15 95
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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