问题
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
回答1:
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.
回答2:
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.)
来源:https://stackoverflow.com/questions/4132865/calling-another-variable-using-a-variable-value-as-parameter-in-jstl