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.
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
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>
0
prainAuthor Commented:
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.
0
CEHJCommented:
Make doPost only call doGet
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

TimYatesCommented:
If only one value can be selected, then instead of:

    String users[]  req.getParameterValues("listOfUsers");

you should be using

    String users  req.getParameter( "listOfUsers" ) ;

Shouldn't it?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prainAuthor Commented:
CEHJ:
Yes I do that even now.

TIm has a point too. Let me try what happens then.
0
prainAuthor Commented:
Thanks Tim. That works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.