我有两个数组列表
private ArrayList<String> userPics = new ArrayList<String>();
private ArrayList<String> picLikes = new ArrayList<String>();
第一个arraylist包含图像的路径,另一个列表包含每个图片得到的no.of。我需要使用iterator标记在struts2中并行获取值。怎么做..?
答案 0 :(得分:0)
假设你是&#34;链接&#34;他们用索引,你可以使用IteratorStatus如下:
<s:iterator value="userPics" var="pics" status="ctr">
Current Element from userPics: <s:property value="pics" />
Current Element from picLikes: <s:property value="picLikes[%{#ctr.index}]" />
</s:iterator>
但创建具有这两个属性的对象以及它们的列表会好10倍:
public class Picture {
private byte[] picture;
private int likes;
/* getters and setters */
}
然后在你的行动中:
private List<Picture> pics;
/* getter and setter */
最后在你的JSP中:
<s:iterator value="pics">
Current Element from userPics: <s:property value="picture" />
Current Element from picLikes: <s:property value="likes" />
</s:iterator>