Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

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("listOfUsers");
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("listOfUsers");
Why is that I get the index instead of the actual string value I get cannot be understod.
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

By "ComboBox", do you mean a multi-select list?

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>
Avatar of prain

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.
Make doPost only call doGet
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prain

ASKER

CEHJ:
Yes I do that even now.

TIm has a point too. Let me try what happens then.
Avatar of prain

ASKER

Thanks Tim. That works.