Struts2 tags seem to evaluate inconsistently

后端 未结 2 1088
你的背包
你的背包 2021-01-22 22:09

I have an issue with some Struts2 tags mixed with OGNL. To overcome the fact that you cannot nest evaluation of expressions in OGNL, e.g., %{foo[%{bar}]}, I use suc

2条回答
  •  无人及你
    2021-01-22 22:56

    First, you are not completely correct saying that you cannot nest evaluation of expressions in OGNL. If you look at the Expression Evaluation of the OGNL Language Gude, you will find that if you use parenthesized expression without a dot in front of the parentheses the result of evaluating that expression will be used as expression to be evaluated. See the example here.

    Second, I don't see the reason for which you are getting indexes other than iterator index.

    Third, the set tag places variables to the value stack context that is accessible via # notation. See the examples here.

    Fourth, answering your direct question:

    Because a typo in the fourth line. Replace the line with

    
    

    will do what expected. You can see the differences in expression.

    The last is just reference to show you where you should use %{} to force evaluation of expression, because Struts is parsing everything (by default) in the tag attributes for OGNL.

    The usage of %{} notation:

    Used in OGNL to force evaluate the content in brackets as OGNL expression.

提交回复
热议问题