wood burning stoves 2.0*
The moose likes Servlets and the fly likes problem with servlet parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with servlet parameter" Watch "problem with servlet parameter" New topic
Author

problem with servlet parameter

Adewale Adebusoye
Ranch Hand

Joined: Sep 28, 2005
Posts: 118
I have a class to upload files from my HTML page to a servlet. The problem is that on the HTML form, if i put an input text box along side the file input box, the servlet always returns null when i try to get the string parameter from the text input.

so i have a text input called empname on my file upload page and when i say
String s=request.getParameter("empname"); it returns null.
But when i remove the file input, it works.
How can i resolve this? Cos i need both of them on the same page.


"Human beings can alter their lives by altering their state of mind" William James
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
I am betting that your HTML form tags are not correctly formatted.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think its just because of the form type. If the form type is multipart/data then you cant get the parameter using request.getParameter("string"). You will surely get null.

Use Apache Commons Fileupload.
Nila dhan
Ranch Hand

Joined: Sep 15, 2005
Posts: 160
Adeel,cud u plz shed more light on form type?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by nila dhan:
Adeel,cud u plz shed more light on form type?


Pardon, if it confused you folks. I meant to say enctype, an attribute of form element.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

cud u plz shed more light


nila, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Adeel is correct. The getParameter and similar methods will not work on forms submitted with a multi-part form encoding (enctype).

You will need to parse out the parameters on your own.

If you are using one of the popular 3rd-party upload packages (jakarta, o'reilly), they provide facilities to obtain the request parameters.
 
GeeCON Prague 2014
 
subject: problem with servlet parameter