[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

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.
0
prain
Asked:
prain
  • 3
  • 2
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now