I am developing a simple web application in which I want to take the option label of a dropdown list in HTML page on the next JSP page. I am using MVC pattern and thus Servlet as a controller will be redirecting (forwarding?) the request to JSP view.
The request.getParameter()
gives me only the option value. But in my case the option value and label are different. How can I get the option label?
You need to maintain a mapping of option values and labels in the server side. E.g. inside some
ServletContextListener
or perhaps servlet'sinit()
:When you put it in the application scope as
${countries}
, then you can display it as follows:This way you will be able to obtain the label in the server side as follows:
Or to display plain in JSP:
Or to pre-select the dropdown:
This can be done without storing anything on server side.