sitijaafar
asked on
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("le arnCountry ")
below is the list box code:
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>
ASKER
I already use request.getParameter("valu e") 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
For example:
UK
US
New Zealend
<< but cannot work,>>
what does this mean? can you share the result of
System.out.println(request .getParame ter("value "));
what does this mean? can you share the result of
System.out.println(request
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!
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());
}
}
}
Use <%= request.getParameter("lear nCountry") %>
-FA
-FA
ASKER
It didn't get the value of the country
<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..
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..
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..
try once without disabling the select box then value will come in servlet..
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.
<select multiple id='learnCountry'
what is output of this <%=disabledLearnMode%>?
req.getParameterValues is correct way to get multiple selected values.
ASKER
Yes, it's multiple list box, so can select multiple values.
ASKER
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.
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.
In servlet are you getting other values correctly?
May be you are not submitting form correctly in JSP.
May be you are not submitting form correctly in JSP.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good
Use <%= request.getParameter("valu
-FA