calling another variable using a variable value as

2019-05-28 19:11发布

the logic is somehow like this:

<c:set var="vehicle" value="car">
<c:set var="car" value="ferrari">

since the value of ${vehicle} = "car" which is also the name of the variable with the value of "ferrari" i access it indirectly using ${'${vehicle}'} but it doesn't seem to work. Can someone help me with this. thanks

标签: java jsp jstl el
2条回答
劫难
2楼-- · 2019-05-28 19:29

I don't think this is supported, and if it was ${'${vehicle}'} wouldn't be the logical syntax for it. (It would be more like ${${vehicle}} ... hypothetically.)

查看更多
孤傲高冷的网名
3楼-- · 2019-05-28 19:31

This kind of things doesn't usually work in java (there's no eval statement). In this case however, the variables are bound to the request context, so I guess you could access it something like this (assuming the variables were assigned to request scope):

${requestScope[vehicle]}

But I can't verify that, because I have not written any JSP code for about 3 years.

查看更多
登录 后发表回答