迭带的方式都一样不过你写的好象不太对劲啊
我写了个例子 你看看吧TestViewObject.javapublic class TestViewObject {
private String userOne;
private String userTwo;
private String userThree; public String getUserOne() {
return userOne;
} public void setUserOne(String userOne) {
this.userOne = userOne;
} public String getUserTwo() {
return userTwo;
} public void setUserTwo(String userTwo) {
this.userTwo = userTwo;
} public String getUserThree() {
return userThree;
} public void setUserThree(String userThree) {
this.userThree = userThree;
}
}TestAction.java
import java.util.ArrayList;
import java.util.List;import struts.vo.TestViewObject;import com.opensymphony.xwork2.ActionSupport;public class TestAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private TestViewObject vo;
List<TestViewObject> list; public TestViewObject getVo() {
return vo;
} public void setVo(TestViewObject vo) {
this.vo = vo;
} public List<TestViewObject> getList() {
return list;
} public String execute() throws Exception {
TestViewObject vo;
list = new ArrayList<TestViewObject>();
for (int i = 0; i < 3; i++) {
vo = new TestViewObject();
vo.setUserOne(i + " gaga");
vo.setUserTwo(i + " dudu");
vo.setUserThree(i + " haha");
list.add(vo);
}
return "success";
}
}
struts.xml<?xml version="1.0" encoding="GBK" ?>
<!--指定struts2配置文件的DTD信息-->
<!DOCTYPE struts PUBLIC
"-//apache Software Foundation//DTD Struts Configuation 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- struts 是struts2配置文件的根元素-->
<struts>
<include file="struts-default.xml"></include>
<!--struts2的Action必须放在指定的包空间下定义-->
<package name="test" extends="struts-default">
<action name="testAction" class="TestAction">
<result>/success.jsp</result>
</action>
</package>
</struts>
success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<body>
<s:iterator value="list">
<s:property value="userOne" />
<s:property value="userTwo" />
</s:iterator>
</body>
</html>
我写了个例子 你看看吧TestViewObject.javapublic class TestViewObject {
private String userOne;
private String userTwo;
private String userThree; public String getUserOne() {
return userOne;
} public void setUserOne(String userOne) {
this.userOne = userOne;
} public String getUserTwo() {
return userTwo;
} public void setUserTwo(String userTwo) {
this.userTwo = userTwo;
} public String getUserThree() {
return userThree;
} public void setUserThree(String userThree) {
this.userThree = userThree;
}
}TestAction.java
import java.util.ArrayList;
import java.util.List;import struts.vo.TestViewObject;import com.opensymphony.xwork2.ActionSupport;public class TestAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private TestViewObject vo;
List<TestViewObject> list; public TestViewObject getVo() {
return vo;
} public void setVo(TestViewObject vo) {
this.vo = vo;
} public List<TestViewObject> getList() {
return list;
} public String execute() throws Exception {
TestViewObject vo;
list = new ArrayList<TestViewObject>();
for (int i = 0; i < 3; i++) {
vo = new TestViewObject();
vo.setUserOne(i + " gaga");
vo.setUserTwo(i + " dudu");
vo.setUserThree(i + " haha");
list.add(vo);
}
return "success";
}
}
struts.xml<?xml version="1.0" encoding="GBK" ?>
<!--指定struts2配置文件的DTD信息-->
<!DOCTYPE struts PUBLIC
"-//apache Software Foundation//DTD Struts Configuation 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- struts 是struts2配置文件的根元素-->
<struts>
<include file="struts-default.xml"></include>
<!--struts2的Action必须放在指定的包空间下定义-->
<package name="test" extends="struts-default">
<action name="testAction" class="TestAction">
<result>/success.jsp</result>
</action>
</package>
</struts>
success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<body>
<s:iterator value="list">
<s:property value="userOne" />
<s:property value="userTwo" />
</s:iterator>
</body>
</html>
return list;
}
JSP页面通过这个方法获得list属性 页面迭代的时候
<s:property value="userOne" />
<s:property value="userTwo" />
他会自动寻找迭代对象里的属性
private String userOne;
private String userTwo;大家都是刚学STRUTS2 互相帮助 ~~
return list;
}
JSP页面通过这个方法获得list属性 页面迭代的时候
<s:property value="userOne" />
<s:property value="userTwo" />
他会自动寻找迭代对象里的属性
private String userOne;
private String userTwo;大家都是刚学STRUTS2 互相帮助 ~~
<tr>
<td>
<s:property value="map.get(#bookId)"/>
</td>
</tr>
</s:iterator>