prain
asked on
ComboBox value supposed to be received from req.getParameterValues is not correct
hi,
I am writing a Java Servlet. I have a ComboBox with name listOfUsers, and a button clickButton. I click the button and at doPost I trap the button click and get the currently displayed value from the comboBox. i use
String users[] req.getParameterValues("li stOfUsers" );
There I get the currently displayed value on the ComboBox. That's good.
Now I click the button again. The second time Instead of the value that appears on the ComboBox I get the index of that value at the same
String users[] req.getParameterValues("li stOfUsers" );
Why is that I get the index instead of the actual string value I get cannot be understod.
I am writing a Java Servlet. I have a ComboBox with name listOfUsers, and a button clickButton. I click the button and at doPost I trap the button click and get the currently displayed value from the comboBox. i use
String users[] req.getParameterValues("li
There I get the currently displayed value on the ComboBox. That's good.
Now I click the button again. The second time Instead of the value that appears on the ComboBox I get the index of that value at the same
String users[] req.getParameterValues("li
Why is that I get the index instead of the actual string value I get cannot be understod.
ASKER
Correct. It a dropdowm list (like a JComboBox). But I have constrained it so that the user really can select only one item.
It generates the page. I have another text box where I put the selected value. I see when I click for the second time it puts the index instead of the actual value string.
In fact I load the contents of the dropdown from a database. I put a print statement in doGet() and I see the values read from the DB and loads into the dropdown is good. but at doPost() it gives me the index.
It generates the page. I have another text box where I put the selected value. I see when I click for the second time it puts the index instead of the actual value string.
In fact I load the contents of the dropdown from a database. I put a print statement in doGet() and I see the values read from the DB and loads into the dropdown is good. but at doPost() it gives me the index.
Make doPost only call doGet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CEHJ:
Yes I do that even now.
TIm has a point too. Let me try what happens then.
Yes I do that even now.
TIm has a point too. Let me try what happens then.
ASKER
Thanks Tim. That works.
The first time you click the button, does it regenerate the page?
If so, View the HTML for the page, I reckon you will see something like:
<option value="1">User 1</option>