第七次学习:
1.迭代显示内容
1.迭代显示内容
java代码: |
1 2 3<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 4<%@ taglib uri="/tags/struts-logic" prefix="logic" %> 5<html> 6 <head> 7 <title>测试 struts-logic Iterate 标签</title> 8 </head> 9 <body bgcolor="white"> 10 定义LIST变量 11 <% ![]()
...}
13 java.
util.
ArrayList list =
new java.
util.
ArrayList
(
);
26 %>
14 list. add ("First" ); 15 list. add ("Second" ); 16 list. add ("Third" ); 17 list. add ("Fourth" ); 18 list. add ("Fifth" ); 19 20 pageContext. setAttribute ("list", list, geContext. PAGE_SCOPE ); 21 定义数组 22 int intArray [ ] = new int [ ] 23 { 0, 10, 20, 30, 40 }; 24 pageContext. setAttribute ("intArray", intArray, PageContext. PAGE_SCOPE ); 25 } 27 <div align="center"> 28 <h1>Test struts-logic Iterate Tag</h1> 29 </div> 30 实例化BEAN 31 <jsp:useBean id="bean" scope="page" class="org. apache. struts. webapp. exercise. TestBean" /> 32 <jsp:useBean id="list" scope="page" class="java. util. ArrayList" /> 33 <h3>测试 1 - Iterate 显示STRING数组 [ 0.. 4 ]</h3> 34 <ol> 35 <logic:iterate id="element" name="bean" property="stringArray" indexId="index"> 36 <li> 37 <em> 38 <bean:write name="element" /> 39 </em> [ 40 <bean:write name="index" /> ]</li> 41 </logic:iterate> 42 </ol> 43 <h3>测试 2 - Iterate 显示数组 [ 0.. 2 ]</h3> 44 <ol> 45 <logic:iterate id="element" name="bean" property="stringArray" indexId="index" length=" 3"> 46 <li> 47 <em> 48 <bean:write name="element" /> 49 </em> [ 50 <bean:write name="index" /> ]</li> 51 </logic:iterate> 52 </ol> 53 <h3>测试 3 - Iterate 显示数组 [ 3.. 4 ]</h3> 54 <ol> 55 <logic:iterate id="element" name="bean" property="stringArray" indexId="index" offset=" 3"> 56 <li> 57 <em> 58 <bean:write name="element" /> 59 </em> [ 60 <bean:write name="index" /> ]</li> 61 </logic:iterate> 62 </ol> 63 <h3>测试 4 - Iterate 显示数组 [ 1.. 3 ]</h3> 64 <ol> 65 <logic:iterate id="element" name="bean" property="stringArray" indexId="index" offset=" 1" length=" 3"> 66 <li> 67 <em> 68 <bean:write name="element" /> 69 </em> [ 70 <bean:write name="index" /> ]</li> 71 </logic:iterate> 72 </ol> 73 <h3>测试 5 - Iterate 显示 List </h3> 74 <ol> 75 <logic:iterate id="item" name="list" indexId="index"> 76 <li> 77 <em> 78 <bean:write name="item" /> 79 </em> [ 80 <bean:write name="index" /> ]</li> 81 </logic:iterate> 82 </ol> 83 <h3>测试 6 - Iterate 显示 List [ 0.. 2 ]</h3> 84 <ol> 85 <logic:iterate id="item" name="list" indexId="index" offset=" 0" length=" 3"> 86 <li> 87 <em> 88 <bean:write name="item" /> 89 </em> [ 90 <bean:write name="index" /> ]</li> 91 </logic:iterate> 92 </ol> 93 <h3>测试 7 - Iterate 显示 List [ 2.. 4 ]</h3> 94 <ol> 95 <logic:iterate id="item" name="list" indexId="index" offset=" 2" length=" 3"> 96 <li> 97 <em> 98 <bean:write name="item" /> 99 </em> [ 100 <bean:write name="index" /> ]</li> 101 </logic:iterate> 102 </ol> 103 <h3>Test 8 - Iterate Over an int array</h3> 104 <ol> 105 <logic:iterate id="item" name="intArray" indexId="index"> 106 <li> 107 <em> 108 <bean:write name="item" /> 109 </em> [ 110 <bean:write name="index" /> ]</li> 111 </logic:iterate> 112 </ol> 113 <h3>Test 9 - Iterate Over an int array [ 0.. 2 ]</h3> 114 <ol> 115 <logic:iterate id="item" name="intArray" indexId="index" length=" 3"> 116 <li> 117 <em> 118 <bean:write name="item" /> 119 </em> [ 120 <bean:write name="index" /> ]</li> 121 </logic:iterate> 122 </ol> 123 <h3>Test 10 - Iterate Over an int array [ 2.. 4 ]</h3> 124 <ol> 125 <logic:iterate id="item" name="intArray" indexId="index" offset=" 2" length=" 3"> 126 <li> 127 <em> 128 <bean:write name="item" /> 129 </em> [ 130 <bean:write name="index" /> ]</li> 131 </logic:iterate> 132 </ol> 133 </body> 134</html> 135 |