I have a JSP with a select input in a form, like so:
<form method="post" action="/confirm">
<select id="dropdown" name="dropdown">
<option value="1">1st choice</option>
<option value="2">2nd choice</option>
<option value="3">3rd choice</option>
</select>
<input type="submit" value="submit" name="submit" />
</form>
I have a spring controller that handles this form as follows:
@RequestMapping(value = "/confirm", method = RequestMethod.POST)
public ModelAndView confirm(@RequestParam int dropdown,
HttpServletRequest request,
Model model)
{
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("selection", dropdown);
modelAndView.setViewName("confirm");
return modelAndView;
}
On my confirm view, if I want to display the value of the dropdown selection then I can do that like this:
<div id="dropselection">${selection}</div>
If the user selected the first option, "1st choice", for example, then the value that would be passed to the confirm page would be 1.
However, what if I want to pass along the text value from the select tag option? What if a user selected the first option and I needed the value 1st choice to be passed into the controller? How would I retrieve that?