EL expression-1, el expression
EL provides the. and [] operators to navigate data. The two represent the same:
$ {SessionScope. user. sex}
Equal
$ {SessionScope. user ["sex"]}
. And [] can also be used together, as follows:
$ {SessionScope. shoppingCart [0]. price}
The returned result is the price of the first item in shoppingCart.
However, there are two differences between the two:
(1) When the attribute name to be accessed contains some special characters, such. or-is not a letter or number, you must use [], for example: $ {user. my-Name}
The preceding method is incorrect and should be changed to: $ {user ["My-Name"]}.
(2) Let's consider the following situations:
$ {SessionScope. user [data]}
In this case, data is a variable. If the value of data is "sex", the above example is equivalent to $ {sessionScope. user. sex };
If the value of data is "name", it is equivalent to $ {sessionScope. user. name }. Therefore, if you want to dynamically set the value, you can use the above method, but you cannot set the dynamic value.