aspose file tools*
The moose likes Servlets and the fly likes request.getParameter() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameter()" Watch "request.getParameter()" New topic
Author

request.getParameter()

Pradeep Chandrasekharan Nair
Ranch Hand

Joined: Apr 01, 2004
Posts: 48
i am submitting data from a form using enctype=multipart/form-data. i am not able to get the value of text field using request.getParameter() method. but i am able to save the file which is uploaded. is there any other methods to get the value of text field.
Richard Bradford
Ranch Hand

Joined: Apr 20, 2004
Posts: 48
Easy(ish) way to get paramters is to use the Apache commons fileupload.
Otherwise you will have to manually parse the request yourself.
Himanshu Bisht
Ranch Hand

Joined: Aug 27, 2004
Posts: 96
well u won't b able to do it this way.
use mime parser to upload the file.
U can get the package and the tutorial from the new.
Balasubramanian Hitler
Greenhorn

Joined: Feb 04, 2004
Posts: 4
enctype=multipart/form-data can be used for only file upload.
When you are using enctype=multipart/form-data you can get the value from the request ServletInputStream only.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by himanshu bisht:
well u won't b able to do it this way.
use mime parser to upload the file.
U can get the package and the tutorial from the new.


i think pardeep uploaded the file successfully, as he mentioned.
Rahul kapoor
Greenhorn

Joined: Sep 21, 2004
Posts: 16
Apache commons fileupload serves the same purpose. Not only you can upload the file but also read the values in text field.

for more details on the usage refer here
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 140
When you set the form enc type as multipart form data, all the form contents (textboxes,radiobuttons,hiddenfields,....) are encoded in the binary mode and sent to the Server. Each form controls binary data is seperated by a boundary data.

So you need to implement a MIME Parser, which identifies the binary boundary data. and use this boundary to parse the individual form contents.

So instead of re-inventing the wheel, you can use a 3rd party tool.something like Apache's FileUpload component. It has proper documentation. It is been widely used.


Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Dharmanand Singh
Greenhorn

Joined: Oct 27, 2004
Posts: 13
Originally posted by Pradeep Chandrasekharan Nair:
i am submitting data from a form using enctype=multipart/form-data. i am not able to get the value of text field using request.getParameter() method. but i am able to save the file which is uploaded. is there any other methods to get the value of text field.


There are many solutions to your problem if you are ready to embrace some libraries. The solutions and their advantages are as follows:

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

1. Download one of the versions of UploadFile from http://jakarta.apache.org/commons/fileupload/
2. Invoke parseRequest(request) on org.apache.commons.fileupload.FileUploadBase which returns list of org.apache.commons.fileupload.FileItem objects.
3. Invoke isFormField() on each of the FileItem objects. This determines whether the file item is a form paramater or stream of uploaded file.
4. Invoke getFieldName() to get parameter name and getString() to get parameter value on FileItem if it's a form parameter. Invoke write(java.io.File) on 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 (Restricted to those appliaction that use this framework):

Use Struts. Struts 1.1 handles this automatically.
[ November 01, 2004: Message edited by: Dharmanand Singh ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getParameter()
 
Similar Threads
please help me
File uploading and data collection problem
File Upload
problem with multipart/form-data
retaing values