Jstl operations on Map sets

Source: Internet
Author: User

1. Iteration

When the expression value in the items attribute of foreach is Java. util. MAP, the type of the variable named IN VaR is

Java. util. Map. Entry. If Var = entry, use the expression $ {entry. Key} to get the key name.

Use the expression $ {entry. Value} to obtain the value of each entry. This is because java. util. Map. entry objects include getkey and getvalue

The Expression Language complies with the naming conventions of JavaBean.

Example:

<C: foreach items = "$ {map}" Var = "entry">

<C: Out value = "$ {entry. Key}"/>

<C: Out value = "$ {entry. Value}"/>

</C: foreach>

2. Evaluate the value based on the key variable

If you know the key in advance, it is easy to get the value object according to $ {map. Key Value}. What if the key is a variable?

One problem is how to use el to get an object for a given key variable. here we need to use [] in the El expression to solve this problem,

The solution is as follows:

<C: Out value = "$ {map [Key]}"/>

<! -- The map here is the java. util. map object, and the key is a key in the map -->

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.