//Input.jsp 跳转页面
<html>
<body>
<a href="test.action">String test</a>
</body>
</html>//Struts.xml 
<struts>
<package name="test"  extends="struts-default">
</action>
   <action name="test" class="action.test">
   <result name="success">tes.jsp</result>
</action>
</struts>
//action  test
public class test extends ActionSupport{ private List<String> listTest;
private List<student> listBeanTest;
public List<String> getListTest() {
return listTest;
}
public List<student> getListBeanTest() {
return listBeanTest;
}
public void setListBeanTest(List<student> listBeanTest) {
this.listBeanTest = listBeanTest;
}
public void setListTest(List<String> listTest) {
this.listTest = listTest;
}
@Override
public String execute() throws Exception {

listTest =new ArrayList<String>();
listTest.add("hello1");
listTest.add("hello2");
listTest.add("hello3");

listBeanTest = new ArrayList<student>();
listBeanTest.add(new student("xiaohong","40","70."));
listBeanTest.add(new student("xiaozhang","40","70."));
listBeanTest.add(new student("xiaowang","40","70."));
return Action.SUCCESS;
}}
//tes.jsp
用<s:iterator/> <s:property/>怎么将Action 中的 listBeanTest 输出?

解决方案 »

  1.   

    <s:iterator value="listTest">
    <s:property/>
    </s:iterator>
      

  2.   

    student类假如有name,age属性并有get/set方法。<s:iterator value="listBeanTest">
    <s:property value="name"/>
    <s:property value="age"/>
    </s:iterator>
    或者
    <s:iterator value="listBeanTest" id="lst">
    <s:property value="#lst.name"/>
    <s:property value="#lst.age"/>
    </s:iterator>
      

  3.   

    如果是 map<student,student> mapTest 呢?
      

  4.   

    <s:iterator id="lst" value="mapTest" status="status">
    <s:property value="#lst[#status.index][0]"/>
    <s:property value="#lst[#status.index][1]"/>
    .................................
    </s:iterator>
      

  5.   

    map <student,student>
    想怎么显示。简单说明一下.
      

  6.   


    比如 private map<map<student,student>,list<student>> complicateTest
    setter...
    getter...execute中
    student t = new student();
    map<student,student> mp = new HashMap<student,student>();
    mp.put(t,t);
    list<student> ls = new ArrayList<student>();
    ls.add(student);
    complicateTest = new map<map<student,student>,list<student>>();
    complicateTest.put(mp,ls);
    //如果我要显示complicateTest 怎么办
      

  7.   


    嵌套啊,有些东西自己可以摸索摸索呀。<s:iterator value="mapA">
    <s:iterator value="获取mapA里的map">
    </s:iterator>
    </s:iterator>
      

  8.   

    ${} 好像JSTL里面取属性的
    %{} struts2里面取属性的两者皆可按对象的  方式取属性值