This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with servlet parameter

 
Adewale Adebusoye
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am betting that your HTML form tags are not correctly formatted.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adeel,cud u plz shed more light on form type?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic