• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1942
  • Last Modified:

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

0
sitijaafar
Asked:
sitijaafar
  • 5
  • 3
  • 3
  • +2
1 Solution
 
Farzad AkbarnejadCommented:
Hello,
Use <%= request.getParameter("value") %> not getParameterValues method.

-FA
0
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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