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= "Arrys
TR "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 traversing a string string in the 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 traversal of the user object in the map (object) ======<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> <TD&G T;<s:property value= "Value.id"/></td> <td><s:property value= "Value.name"/></td> &L T;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 the map = = = <s:iterator value= "Arraymap" id= MN "> <div><s:property value=" #column "/></div>-------------------key:<s:property value=" Key "/>--------------------<br/> <s:iterator value=" value "id=" col "> <s:property value=" col "/& gt;<br/> </s:iterator> <div></div> </s:iterator> <br/>======iter Ator traversing the list collection in the map = = = <table border= "1" width= "50%" cellpadding= "0" cellspacing= "0" > <tr style= "Backgrou Nd-color:yellow "> <td>key</td> <td>id</td> <td>name</td> <t
d>pwd</td> <td>age</td> </tr> <s:iterator value= "Userlistmap" id= "column" > <s:set var= "Total" name= "Total" value= "#column value.size"/> <s:iterator "#column. Value" value= "id=" status= "St" >;tr> <s:if test= "#st. I" ><td rowspan= "${total}" ><s:property value= "#column. Key"/></td& Gt;</s:if> <td><s:property value= "id"/></td> <td><s:property value= "name"/> ;</td> <td><s:property value= "pwd"/></td> <td><s:property "age" value= ;/td> </tr> </s:iterator> </s:iterator> </table> <br/>======iterator The list collection in traversal object[] = = = = = <table border= "1" width= "50%" cellpadding= "0" cellspacing= "0" > <tr style= "Backgro Und-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><s:property value=" olist[#st. index][1] "/></td> < Td><s:property value="olist[#st. index][2]"/></td> </tr> </s:iterator> </table> </center> & Lt;/body>
I test the wood has the question, welcome everybody to consult
Also enclosed is an introduction to the usage of STRUTS2 traversal sets:
Struts2 's s:iterator can traverse any array within the data stack, set, and so on, for a few simple demos:
The S:iterator label has 3 properties:
Value: A collection of iterations
ID: Specifies the ID of the element within the collection
Index of the status iteration element
1:jsp page definition element style array or list
<s:iterator value= ' {' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '} ' id= ' number ' >
<s:property value= ' number '/>a
</s:iterator>
Print Result: 1a2a3a4a5a
2: Usage of the index
If status is specified, each iteration data has an instance of Iteratorstatus, which has the following methods
How to use status in <s:iterator
1: #status. Odd whether the current element index is an odd row
2: #status. Even whether the current element index is even
Yes
3: #status. Count currently iterates through several elements
4: #status. Index current element index, starting from 0 "#status. count= #status. index+1" 5: #status. Is the first element currently
6: #status. Is the last element currently
7: #status. Modules (int) Current number of rows modulo