使用变量作为键访问EL中的映射值

编程入门 行业动态 更新时间:2024-10-27 08:30:08
本文介绍了使用变量作为键访问EL中的映射值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在EL中有一个Map作为${map},我试图使用一个键来获取它的值,该键本身也是一个EL变量${key},其值是"1000".

I have a Map in EL as ${map} and I am trying to get the value of it using a key which is by itself also an EL variable ${key} with the value "1000".

使用${map["1000"]}可以,但是${map["$key"]}无效.我在做什么错?如何使用变量作为键来获取Map值?

Using ${map["1000"]} works, but ${map["$key"]} does not work. What am I doing wrong and how can I get the Map value using a variable as key?

推荐答案

$不是变量名的开头,它表示表达式的开头.您应该使用${map[key]}来访问地图map中的属性key.

$ is not the start of a variable name, it indicates the start of an expression. You should use ${map[key]} to access the property key in map map.

您可以在带有GET参数的页面上尝试使用以下查询字符串,例如?whatEver=something

You can try it on a page with a GET parameter, using the following query string for example ?whatEver=something

<c:set var="myParam" value="whatEver"/> whatEver: <c:out value="${param[myParam]}"/>

这将输出:

whatEver: something

请参阅: stackoverflow/tags/el/info 并滚动到括号符号"部分.

See: stackoverflow/tags/el/info and scroll to the section "Brace notation".

更多推荐

使用变量作为键访问EL中的映射值

本文发布于:2023-11-23 17:34:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   EL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!