The collection types defined in the class are as follows: Private String [] arrystr;private list<user> list;private map<string,string> map;private Map <Integer,User> usermap;private map<string,string[]> arraymap;private map<string,list<user> > Userlistmap;private list<object[]> olist;
The corresponding use of the struts2 tag in the JSP page is traversed as follows:
<body> <center> <br/>======iterator Traversal string character array ======<br/> <s:iterator value= "Arrystr" Id= "Array" > <s:property value= "array"/><br/> </s:iterator> <div></div> <br/> ======iterator Traversal List collection ======<br/> <table border= "1" width= "50%" cellpadding= "0" cellspacing= "0" > <tr style= "Background-color:yellow" > <td>id</td> <td>name</td> <td>pwd</td> <td>age</td> </tr> <s:iterator value= "list" id= "array" > <tr> <td><s:property Value= "id"/></td> <td><s:property value= "name"/></td> <td><s:property value= " PWD "/></td> <td><s:property value=" age "/></td> </tr> </s:iterator> </ Table> <br/>======iterator Traversal string string in map ======<br/> <s:iterator value= "map" id= "column" > <s:property value= "#column"/><br/> key:<S:property value= "key"/><br/> value:<s:property value= "value"/><br/> </s:iterator> < Div></div> <br/>======iterator traverse the User Object (object) in map ======<br/> <table border= "1" width= "50 % "cellpadding=" 0 "cellspacing=" 0 "> <tr style=" Background-color:yellow "> <td>key=value</td> <td>id</td> <td>name</td> <td>pwd</td> <td>age</td> </tr> <s:iterator value= "UserMap" id= "column" > <tr> <td><s:property value= "#column"/></td> & Lt;td><s:property value= "Value.id"/></td> <td><s:property value= "Value.name"/></td > <td><s:property value= "value.pwd"/></td> <td><s:property value= "Value.age"/> </td> </tr> </s:iterator> </table> <br/>======iterator traversing a string character array in map ====== <s: Iterator value= "Arraymap" id= "column" > <div><s:property Value= "#column"/></div>-------------------key:<s:property value= "key"/>--------------------< br/> <s:iterator value= "value" id= "col" > <s:property value= "col"/><br/> </s:iterator> < Div></div> </s:iterator> <br/>======iterator traverse the list collection in map ====== <table border= "1" width= "50 % "cellpadding=" 0 "cellspacing=" 0 "> <tr style=" Background-color:yellow "> <td>key</td> <td >id</td> <td>name</td> <td>pwd</td> <td>age</td> </tr> <s: Iterator value= "Userlistmap" id= "column" > <s:set var= "Total" name= "Total" value= "#column. Value.size"/> <s : Iterator value= "#column. Value" id= "col" status= "St" > <tr> <s:if test= "#st. First" ><td rowspan= "${ Total} "><s:property value=" #column. Key "/></td></s:if> <td><s:property value=" id "/ ></td> <td><s:property value= "name"/></td> <td><s:property value= "pwd"/></td> <td><s:property value= "age"/></td> </tr> </s:iterator> </s:iterator> </table> <br/>======iterator traversing the list collection in object[] = = = = <table border= "1" width= "50%" cellpadding= "0" cellspacing= "0" > <tr style= "Background-color:yellow" > < ;td>key</td> <td>id</td> <td>name</td> </tr> <s:iterator value= "Olist" id= "Value" status= "St" > <tr> <td><s:property value= "olist[#st. index][0]"/></td> <td>& Lt;s:property value= "olist[#st. index][1]"/></td> <td><s:property value= "olist[#st. index][2]"/ ></td> </tr> </s:iterator> </table> </center> </body>
I test the wood has a problem, welcome everyone reference
Also attached is an introduction to the usage of the STRUTS2 traversal set:
Struts2 's s:iterator can traverse any array in the data stack, the collection and so on the following simple demo:
The S:iterator tag has 3 properties:
Value: The collection that is iterated
ID : The ID of the element within the specified collection
The index of the status Iteration Element
1:jsp page definition elements array or list
<s:iterator value= "{' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '}" id= ' number ' >
<s:property value= ' number '/>a
</s:iterator>
Printing Result: 1a2a3a4a5a
2: Use of the index
If status is specified, each iteration of the data has an instance of Iteratorstatus, and it has the following methods
How to use status in <s:iterator
1: #status. Odd whether the current element index is an odd line
2: #status. Even whether the current element index is even
Yes
3: #status. Count currently iterates over several elements
4: #status. Index of the current element, starting from 0 #status. count= #status. Index+1 "
5: #status The first element of the current
6: #status. Last is currently the final element
7: #status. Modules (int) modulo the current number of rows
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Struts2 tags traverse various forms of data collection