Solved

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

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

Expert Comment

by:objects
ID: 11797989
what problems exactly are you having with oreilly?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Session migration 1 93
Need to view directory list in apache/tomcat 9 106
issue with pdf generation 2 78
java operators 3 90
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now