start.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<a href="address"><s:iterator/>标签用法演示</a>
</body>
</html>struts.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="address" class="action.SampleAction">
<result name="success">/showInfo.jsp</result>
</action>
</package>
</struts>Address.java :
public class Address {
private String street;
private String zipcode;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public Address() {
super();
}
public Address(String street, String zipcode) {
super();
this.street = street;
this.zipcode = zipcode;
}
}SampleAction.java :
public class SampleAction {
private List<Address> adds=new ArrayList<Address>();
public List<Address> getAdds() {
return adds;
}
public void setAdds(List<Address> adds) {
this.adds = adds;
}
public String execute(){
for(int i=1;i<=9;i++){
adds.add(new Address("文三路"+i+"号","10020"+i));
}
return "success";
}
}
showInfo.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<ul>
<s:iterator var="address" value="adds" status="stat">
<li>
<s:property value="#stat.count"/>
<s:property value="#address.street"/>
<s:property value="#address.zipcode"/>
</li>
</s:iterator>
</ul>
<s:debug></s:debug>
</body>
</html>
1163

被折叠的 条评论
为什么被折叠?



