JSP expression language and dynamic attribute names

前端 未结 1 854
野趣味
野趣味 2020-12-18 02:05

I\'m trying to do something that seems like it should be relatively straightforward and running into a bit of a wall.

Let\'s say I\'ve got a list of products which

相关标签:
1条回答
  • 2020-12-18 02:18

    You can by using implicit objects:

    There are objects that allow access to the various scoped variables described in Using Scope Objects.

    • pageScope: Maps page-scoped variable names to their values
    • requestScope: Maps request-scoped variable names to their values
    • sessionScope: Maps session-scoped variable names to their values
    • applicationScope: Maps application-scoped variable names to their values
    When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.

    So, for example:

    <c:set var="selectedProductAttrName" value="selectedProduct_${product.id}"/>
    ${requestScope[selectedProductAttrName]}
    
    0 讨论(0)
提交回复
热议问题