1. 普通属性
public String execute(){
username = "zhangsan";
password = "123";
}
<s:property value="username"/><br>
<s:property value="password"/><br>
2. 自定义对象
public String execute(){
userInfo = new UserInfo();
userInfo.setUsername("hhh");
userInfo.setPassword("111");
}
<s:property value="userInfo.username"/><br>
<s:property value="userInfo.password"/><br>
3. List(普通属性)
public String execute(){
list = new ArrayList<String>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
}
<s:iterator value="list" var="var">
<s:property value="var"/><br>
</s:iterator>
或者:
<s:iterator value="list">
<s:property/><br>
</s:iterator>
4. List(自定义对象属性)
public String execute(){
list = new ArrayList<UserInfo>();
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u1");
userInfo.setPassword("p1");
userInfo.setRoleInfo(new RoleInfo("r1"));
list.add(userInfo);
userInfo = new UserInfo();
userInfo.setUsername("u2");
userInfo.setPassword("p2");
userInfo.setRoleInfo(new RoleInfo("r2"));
list.add(userInfo);
}
<s:iterator value="list" var="var">
<s:property value="#var.username"/>
<s:property value="#var.password"/>
<s:property value="#var.roleInfo.rolename"/><br>
</s:iterator>
或者:
<s:iterator value="list">
<s:property value="username"/>
<s:property value="password"/>
<s:property value="roleInfo.rolename"/><br>
</s:iterator>
5. 数组(普通属性)
public String execute(){
strs = new String[2];
strs[0] = "as";
strs[1] = "asd";
}
<s:iterator value="strs">
<s:property/><br>
</s:iterator>
或者:
<s:iterator value="strs" var="var">
<s:property value="var"/><br>
</s:iterator>
6. 数组(自定义对象属性)
public String execute(){
strs = new UserInfo[2];
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u11");
userInfo.setPassword("11");
strs[0] = userInfo;
userInfo = new UserInfo();
userInfo.setUsername("u22");
userInfo.setPassword("22");
strs[1] = userInfo;
}
<s:iterator value="strs">
<s:property value="username"/>
<s:property value="password"/><br>
</s:iterator>
或者:
<s:iterator value="strs" var="var">
<s:property value="#var.username"/>
<s:property value="#var.password"/><br>
</s:iterator>
7. 数组(自定义对象属性)
public String execute(){
strs = new UserInfo[2];
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u11");
userInfo.setPassword("11");
userInfo.setRoleInfo(new RoleInfo("r11"));
strs[0] = userInfo;
userInfo = new UserInfo();
userInfo.setUsername("u22");
userInfo.setPassword("22");
userInfo.setRoleInfo(new RoleInfo("r22"));
strs[1] = userInfo;
}
<s:iterator value="strs" var="var">
<s:property value="#var.username"/>
<s:property value="#var.password"/>
<s:property value="#var.roleInfo.rolename"/><br>
</s:iterator>
或者:
<s:iterator value="strs">
<s:property value="username"/>
<s:property value="password"/>
<s:property value="roleInfo.rolename"/><br>
</s:iterator>
8. Map(普通属性)
public String execute(){
map = new HashMap<String,String>();
map.put("k1", "v1");
map.put("k2", "v2");
}
<s:iterator value="map" var="var">
<s:property value="#var.key"/>
<s:property value="#var.value"/><br>
</s:iterator>
或者:
<s:iterator value="map">
<s:property value="key"/>
<s:property value="value"/><br>
</s:iterator>
9. Map(自定义对象属性)
public String execute(){
map = new HashMap<String,UserInfo>();
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u1");
userInfo.setPassword("p1");
userInfo.setRoleInfo(new RoleInfo("r1"));
map.put("k1", userInfo);
userInfo = new UserInfo();
userInfo.setUsername("u2");
userInfo.setPassword("p2");
userInfo.setRoleInfo(new RoleInfo("r2"));
map.put("k2", userInfo);
}
<s:iterator value="map" var="var">
<s:property value="#var.key"/>
<s:property value="#var.value.username"/>
<s:property value="#var.value.password"/>
<s:property value="#var.value.roleInfo.rolename"/><br>
</s:iterator>
或者
<s:iterator value="map">
<s:property value="key"/>
<s:property value="value.username"/>
<s:property value="value.password"/>
<s:property value="value.roleInfo.rolename"/><br>
</s:iterator>
10. Map嵌套Map(自定义对象属性)
public String execute(){
map = new TreeMap<String,Map<String,UserInfo>>();
Map<String,UserInfo> innerMap = new TreeMap<String,UserInfo>();
UserInfo userInfo = new UserInfo();
userInfo.setUsername("u1");
userInfo.setPassword("p1");
userInfo.setRoleInfo(new RoleInfo("r1"));
userInfo = new UserInfo();
userInfo.setUsername("u11");
userInfo.setPassword("p11");
userInfo.setRoleInfo(new RoleInfo("r11"));
innerMap.put("k1", userInfo);
innerMap.put("k11", userInfo);
map.put("key1", innerMap);
//
innerMap = new TreeMap<String,UserInfo>();
userInfo = new UserInfo();
userInfo.setUsername("u2");
userInfo.setPassword("p2");
userInfo.setRoleInfo(new RoleInfo("r2"));
userInfo = new UserInfo();
userInfo.setUsername("u22");
userInfo.setPassword("p22");
userInfo.setRoleInfo(new RoleInfo("r22"));
innerMap.put("k2", userInfo);
innerMap.put("k22", userInfo);
map.put("key2", innerMap);
}
<s:iterator value="map" var="var">
<s:iterator value="value">
<s:property value="#var.key"/>
<s:property value="key"/>
<s:property value="value.username"/>
<s:property value="value.password"/>
<s:property value="value.roleInfo.rolename"/><br>
</s:iterator>
</s:iterator>