Aquarius24 Aquarius24 - 2 months ago 7
Java Question

Get selected dropdown value in servlet

I have below dropdown value in html and I am sending data to servlet using get method

<select name="country">
<option value="IN">India</option>
<option value="AU">Australia</option>
<option value="US">United States</option>
</select>


in servlet
when i do
request.getParameter("country");
i am getting IN, AU and US
instead of real country name

Answer

Use

<select name="country">
<option>India</option>
<option>Australia</option>
<option>United States</option>
</select>

Instead.

Or use the direct BCP47-Code (https://tools.ietf.org/html/bcp47)

 Locale.forLanguageTag(request.getParameter("country"))
    .getDisplayCountry(Locale.forLanguageTag("en_US"));

Page 4 sais 2 ALPHA-Characters are minimum for locale:

language = 2*3ALPHA ; shortest ISO 639 code

Comments