下面是舉的一個例子你可以考到有struts 2環境的項目中看一下。
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@ taglib prefix="s" uri="/struts-tags" %>
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <head>
6 <title>My JSP 'index.jsp' starting page</title>
7 <meta http-equiv="pragma" content="no-cache">
8 <meta http-equiv="cache-control" content="no-cache">
9 <meta http-equiv="expires" content="0">
10 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
11 <meta http-equiv="description" content="This is my page">
12 <!--
13 <link rel="stylesheet" type="text/css" href="styles.css">
14 -->
15 <s:head/>
16 </head>
17
18 <body>
19 <table border="0">
20 <tr>
21 <s:iterator value="{'banana','apple','orange','cherry'}" id="fruitName" status="st">
22 <td><s:property value="fruitName"/></td>
23 <s:if test="(#st.index+1)%3==0"><!-- #st.index獲取數組的下標 -->
24 </tr><tr>
25 </s:if>
26 </s:iterator>
27 </tr>
28 </table>
29 </body>
30 </html>
2 <%@ taglib prefix="s" uri="/struts-tags" %>
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <head>
6 <title>My JSP 'index.jsp' starting page</title>
7 <meta http-equiv="pragma" content="no-cache">
8 <meta http-equiv="cache-control" content="no-cache">
9 <meta http-equiv="expires" content="0">
10 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
11 <meta http-equiv="description" content="This is my page">
12 <!--
13 <link rel="stylesheet" type="text/css" href="styles.css">
14 -->
15 <s:head/>
16 </head>
17
18 <body>
19 <table border="0">
20 <tr>
21 <s:iterator value="{'banana','apple','orange','cherry'}" id="fruitName" status="st">
22 <td><s:property value="fruitName"/></td>
23 <s:if test="(#st.index+1)%3==0"><!-- #st.index獲取數組的下標 -->
24 </tr><tr>
25 </s:if>
26 </s:iterator>
27 </tr>
28 </table>
29 </body>
30 </html>