public class disp extends ActionSupport{
private List <Disp> list;public void setList(List list){
  this.list = list;
}
public void getList(){
  return list;
}
public String execute(){
  DispImpl dao = new DispImpl();
  list = dao.GetAll();
  return  SUCCESS;
}然后在页面用Struts2的标签取这个list。

解决方案 »

  1.   

    1  在Action中把list保存(比如可以保存在request或session中)。此处保存在request中。
         request.setAttribute("list",list).
    2   在jsp中,使用 <logic:iterate>标签遍历显示。
    <logic:iterate id="elem" name="list" >
         <bean:write name="elem">
    </logic:iterate>
      

  2.   


    感谢你的解答,我是个新手,请问应该jsp页面应该怎么写呢?麻烦了~
      

  3.   

    我知道struts1里面可以用您说的那个方法,但是我用的是struts2似乎没有request方法。
    我想知道struts2里面应该怎么取得。
      

  4.   

    <s:iterator id="rv" value="list">
    <s:property id="rv" value="content"/>
    </s:iterator>list里面保存的是个对象,content只是这个对象的属性名而已
      

  5.   

    感谢:qq7338367、duanyuana 的回答,问题已经解决了。请问怎么把分给你们?不太会用……
      

  6.   

    前面楼上有正解了,,,保存到request或session中然后在jsp页面用迭逮进行输出
      

  7.   

    另外,还有个附加问题,如果我不想用get方法获得list的话,能否像struts1那样,将list保存到request或者session中返回呢?应该怎么写呢?struts2似乎没有request.setAttribute("list",list);这个方法。
      

  8.   

    Struts2有com.opensymphony.xwork2.ActionContext这么个类static ActionContext getContext() 
              Returns the ActionContext specific to the current thread. Map getParameters() 
              Returns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise. 还有个ValueStack也可以用
      

  9.   

    想直接操作request对象可以用org.apache.struts2.ServletActionContextHttpServletRequest request = ServletActionContext.getRequest();
      

  10.   

    Action页面
    request.setAttribute("alluser",list);//将查询到的user存放在List中
    JSP页面
    <table>
         <tr><td>用户级别</td><td>用户ID</td><td>用户姓名</td></tr>
      <logic:iterate id="user" name="alluser" scope="request">
      <tr>
      <td>${user.grade}</td>
      <td>${user.userid}</td>
      <td>${user.realname}</td></tr>
      </logic:iterate>
      <tr><td>总页数:</td><td></td><td><a href="user.do">下一页</a></td></tr>
        </table>
    id :指定输出元素的名 与 <bean:write> 中name 属性一致
    name :request 中的集合名, 从中取循环取出元素
      

  11.   

    在action中加
    request.setAttribute("list",list). 
    在jsp中加
    List list = request。getAttribute("list");
      

  12.   

    xiao huo zi bu cuo,hehe
      

  13.   

    Action 中ActionContext.getContext().put("test", "00000");这个就相当于 struts1.x 中的request.setAttribute("test","00000");页面 可以用 jsp 的标签取值
    也可以用 (Sring)request.getAttribute("test");