Using a variable using a variable value in EL
I want to access a variable of type Map
from my model using EL. e.g.
${name} = "mycar"
${mycar} = "ferrari"
I tried ${${name}}
but it doesn't work. The expected value is "ferrari". What do you think is the co开发者_运维知识库rrect syntax for this?
I don't think you can do that. However, you can have a Map
in your Java code that will be accessible using ${myMap[myValue]}
. So for example, in your JSP page you will have:
<c:set var="name" value="mycar"/>
<c:set var="myCar" value="${carsMap[name]}"/>
it's like you called carsMap.get("mycar");
in Java...
You can then loop around your map
.
<c:forEach var="entry" items="${map}">
${entry.key}: ${entry.value},
</c:forEach>
精彩评论