Get list box value in servlet

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

sitijaafarAsked:
Who is Participating?
 
Gurvinder Pal SinghConnect With a Mentor Commented:
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
 
Farzad AkbarnejadDeveloperCommented:
Hello,
Use <%= request.getParameter("value") %> not getParameterValues method.

-FA
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
sitijaafarAuthor Commented:
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
 
Gurvinder Pal SinghCommented:
<< but cannot work,>>
what does this mean? can you share the result of
System.out.println(request.getParameter("value"));
0
 
Farzad AkbarnejadDeveloperCommented:
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
 
Farzad AkbarnejadDeveloperCommented:
Use <%= request.getParameter("learnCountry") %>

-FA
0
 
sitijaafarAuthor Commented:
It didn't get the value of the country
0
 
chaitu chaituCommented:
<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
 
chaitu chaituCommented:
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
 
ManishLeadCommented:
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
 
sitijaafarAuthor Commented:
Yes, it's multiple list box, so can select multiple values.
0
 
sitijaafarAuthor Commented:
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
 
ManishLeadCommented:
In servlet  are you getting other values correctly?
May be you are not submitting form correctly in JSP.

0
 
sitijaafarAuthor Commented:
Good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.