EL expression-1, el expression

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.