Select drop down value retrieval
문제
I have the following data
<select class="small" name="test"><option value="1">a</option>
i want to print 'a' how can i do it?
request.getparameter(test)
gives me the selected value like 1
해결책
You can't, at least not this way.
The general flow is this
- You have some model, containing both values (let's call them "value" and "display value")
- You output the
<select>
in a jsp and iterate over that model - When the form is submitted back to the servlet/jsp, you get the "value" and, based on your model, get the corresponding "display value"
As pointed out in the comment below, the most widely used model is a Map
implementation. TreeMap
. HashMap
, LinkedHashMap
, depending on your data.
제휴하지 않습니다 StackOverflow