Output values in map using the jstl Loop

Source: Internet
Author: User

Since El expressions do not support cyclically output values in map, jstl must be used to traverse map cyclically.

This is the action corresponding to map.

Public actionforward execute (actionmapping mapping, actionform form,
Httpservletrequest request, httpservletresponse response)
Throws exception {

Map map = new hashmap ();
Map. Put ("K1", "Feng jianghong, you are ridiculous ");
Map. Put ("K2", "you can't think of today ");
Map. Put ("K3", "This is a bitter taste, have you tasted it ");

Request. setattribute ("maps", MAP );



Return Mapping. findforward ("success ");
}

 

 

The page can be retrieved like this

<Li> use the jstl loop to get all values in Map </LI> <br>
<C: foreach items = "$ {maps}" Var = "map">
Map key: $ {map. Key} <br>
MAP value: $ {map. Value} <br>

</C: foreach>

 

 

What are the elements in the map set? It is a map. Entry object, which includes the getkey () and getvalue () methods.

Therefore, you can use the El expression map on the page and click the navigation key to retrieve the key value 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.