小编典典
您需要在服务器端维护选项值和标签的映射。例如,在某些ServletContextListener甚至是servlet的内部init():
Map countries = new LinkedHashMap();
countries.put("CW", "Curaçao");
countries.put("NL", "The Netherlands");
countries.put("US", "United States");
// ...
servletContext.setAttribute("countries", countries);
将其作为放在应用程序范围中时${countries},可以显示如下:
${country.value}
这样,您将可以在服务器端获取标签,如下所示:
Map countries = (Map) getServletContext().getAttribute("countries");
// ...
String countryCode = request.getParameter("country");
String countryName = countries.get(countryCode);
// ...
或在JSP中简单显示:
Country code: ${param.country}
Country name: ${countries[param.country]}
或预选下拉菜单:
${country.value}
2020-06-08