JSTL - how to get value?

I have this on my jsp page: ${category.name_ENG} , which has "Auto" as the value

but I have a local language in another varialbes: ${locale} . So in my jsp I want to display the value of the car depending on the locale variable.

I tried:

 ${category.name_${locale}} ${category['name_${locale}']} ${category['name_{locale}']} 

but none of them worked? any help?

+4
source share
1 answer

Use JSTL <c:set> to concatenate a string in EL, and then use the legend [] to access properties using a dynamic key.

 <c:set var="name" value="name_${locale}" /> ${category[name]} 

By the way, if the only functional requirement is internationalization / localization, then there are much better ways than messing around like this: How to internationalize a Java web application?

+5
source

All Articles