JSTL-如何获得价值的价值? [英] JSTL - how to get a value of value?
问题描述
我在jsp页面中有此文件:${category.name_ENG}
,其中汽车"为值
I have this in my jsp page : ${category.name_ENG}
which has "Car" as value
但是我有另一种当地语言的本地语言:${locale}
.因此,在我的jsp中,我想根据locale变量显示汽车价值.
but i have the local language in an another varialbes : ${locale}
. So in my jsp i want to display the car value depending on the locale variable.
我尝试了那些:
${category.name_${locale}}
${category['name_${locale}']}
${category['name_{locale}']}
但是他们都没有工作吗? 有帮助吗?
but none of them worked? any help?
推荐答案
使用JSTL <c:set>
连接EL中的字符串,然后使用大括号表示法[]
来访问具有动态键的属性.
Use JSTL <c:set>
to concatenate a string in EL and then use brace notation []
to access properties with a dynamic key.
<c:set var="name" value="name_${locale}" />
${category[name]}
顺便说一句,如果唯一的功能要求是国际化/本地化,那么还有比这样摆弄更好的方法:
By the way, if the sole functional requirement is internationalization/localization, then there are way much better ways than fiddling like this: How to internationalize a Java web application?
这篇关于JSTL-如何获得价值的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!