在struts2:OGNL表達式,遍歷List、Map集合;投影的使用一文中已經講述了OGNL遍歷List、Map集合等功能。html
本文簡單寫一個遍歷數組的示範程序。java
<% String[] myArray = new String[]{"你好","我好","你們好"}; request.setAttribute("myArray", myArray); %> <s:iterator value="#request.myArray" status="st"> <s:iterator value="#request.myArray[#st.index]"> <s:property /> <br/> </s:iterator> </s:iterator>
輸出:數組
Action類UploadTest2Action,引用FileUploadTools類;FileUploadTools類中包含uploadFileFileName的數組,要求在JSP中遍歷此數組。post
UploadTest2Action.javathis
public class UploadTest2Action extends ActionSupport { private FileUploadTools fileUploadTools = new FileUploadTools(); // ...... }
FileUploadTools.javaurl
public class FileUploadTools { private String uploadFileFileName[];// 文件名是數組類型 public String[] getUploadFileFileName() { return uploadFileFileName; } public void setUploadFileFileName(String[] uploadFileFileName) { this.uploadFileFileName = uploadFileFileName; } // ...... }
JSP中引用spa
<s:iterator value="fileUploadTools.uploadFileFileName" status="st"> <s:iterator value="fileUploadTools.uploadFileFileName[#st.index]"> <s:property /> <br/> </s:iterator> </s:iterator>
輸出:code
略htm