Solved

Get list box value in servlet

Posted on 2010-09-20
15
1,734 Views
Last Modified: 2012-05-10
Hi experts, I'm having a problem in getting a value of list box in servlet.  For get the value I already used this code : req.getParameterValues("learnCountry")

below is the list box code:
<select id='learnCountry' name='learnCountry' size="6" style="width:200px" <%=disabledLearnMode%>>
						  <%
							String [] country2= country.split(",");
							for(int h=0; h<country2.length; h++) {
							 String select=country2[h];%>
							<option value='<%=country2[h]%>'> <%=select%> </option>	
							<%}%>							
							
						 </select>	

Open in new window

0
Comment
Question by:sitijaafar
  • 5
  • 3
  • 3
  • +2
15 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 33714887
Hello,
Use <%= request.getParameter("value") %> not getParameterValues method.

-FA
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33714905
0
 

Author Comment

by:sitijaafar
ID: 33714917
I already use request.getParameter("value")  but cannot work, this because in the list box have a multiple value because after I add the list of option I want to get all the values:
For example:
         UK
         US
         New Zealend
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33714928
<< but cannot work,>>
what does this mean? can you share the result of
System.out.println(request.getParameter("value"));
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 33714947
Hello,
Actually...  with a MULTIPLE select box, you will need to use a
StringTokenizer, since the parameter value will be a comma separated
list of all select options...



Hope that helps!

for (Enumeration p = request.getParameterNames() ; p.hasMoreElements();) {
   name = p.nextElement().toString() ;
   value = req.getParameter(name) ;
   if(name.equals("NAME")) {
      st = new StringTokenizer(value, ",");
      while (st.hasMoreTokens()) {
         // do something with each token.
         System.err.println(st.nextToken());
      }
   }
}

Open in new window

0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 33714958
Use <%= request.getParameter("learnCountry") %>

-FA
0
 

Author Comment

by:sitijaafar
ID: 33714966
It didn't get the value of the country
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 33715006
<select id='learnCountry' name='learnCountry' size="6" style="width:200px" <%=disabledLearnMode%>>

i think  the select box is disabled in your code then value will not come in servlet.

try once without  disabling the select box then value will come in servlet..
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 33715214
don't use <%=disabledLearnMode%> in select tag ;i think you are disabling the select box.

try once without  disabling the select box then value will come in servlet..

0
 
LVL 11

Expert Comment

by:Manish
ID: 33715576
First , is it multiple select box?  Add multiple
<select multiple id='learnCountry'
what is output of this  <%=disabledLearnMode%>?
req.getParameterValues is correct way to get multiple selected values.




0
 

Author Comment

by:sitijaafar
ID: 33721800
Yes, it's multiple list box, so can select multiple values.
0
 

Author Comment

by:sitijaafar
ID: 33721859
I already add <select multiple id='learnCountry'

the <%=disabledLearnMode%> is for disabled the list box.  Because I have make an option whether to disable it or not.  In current situuation I'm not disabled it. In the servlet I used req.getParameterValues and the result is null also when used req.getParameter.
0
 
LVL 11

Expert Comment

by:Manish
ID: 33722275
In servlet  are you getting other values correctly?
May be you are not submitting form correctly in JSP.

0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33722307
can you show how you are submitting the values? and also like fellow expert @karanw is suggesting, please check if other values are getting submitted properly

Would suggest that you check the view source from browser and see if the select bpx is disabled or not.

Let me know the result of
System.out.println(request.getParameter("learnCountry"));
0
 

Author Closing Comment

by:sitijaafar
ID: 33926687
Good
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
twoTwo  challenge 35 86
ShiftLeft challenge 21 66
abstract class with all non abstract mentods 6 71
eclipse formatting 6 41
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now