html从下拉菜单中选择,如何从下拉列表中选择选项标签?

小编典典

您需要在服务器端维护选项值和标签的映射。例如,在某些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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值