On the jsp page, how does one obtain the values of a specified set in Map and print them cyclically?

Source: Internet
Author: User

I recently encountered some problems when I used jsp to output map data.

The result is that I didn't set the get Method for map in ation (all I have is the ssh framework)

Assume that there is a map variable in the action, and the key-value pair is a set of String and Custom User types, respectively.

Action has the following code, and the action contains the map attribute, map set, and get methods.

Map <String, List <User> map = new HashMap <String, List <User> ();

User user = new User ();

User. setId = 1;

User. setName = "aa ";

List <User> list1 = new ArrayList <User> ();

List1.add (user );

User user2-new User ();

User2.setId = 2;

User2.setName = "bb ";

List1.add (user2 );

User user3 = new User ();
User3.setId = 3;
User3.setName = "cc ";
List <User> list2 = new ArrayList <User> ();
List1.add (user3 );
User user4-new User ();
User4.setId = 4;
User4.setName = "cc ";
List2.add (user4 );
Map. put ("group1", list1 );
Map. put ("group2", list2 );

What should I do if I want to traverse list1 in jsp?
Use struts2 labels

<S: iterator value = "map ['group1']">
<S: property value = "id"/>:< s: property value = "name"/>

<Br/>

</S: iterator>

The page will output

1: aa

2: bb

 

Related Article

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.