我用到两个框架struts2和Hibernate.现在我要把学生的信息从数据库中取出,全部显示在display.jsp中
1'这是到层实现方法:我想问这个list中保存的是什么信息?
public List select(){
Session session =sessionfac.getSession();
Query query = session.createQuery("from Student");
List list = query.list();
session.close();
return list ;
}
2'在Struts2中的Action中该怎么写? 下面是我写的,不知道该怎么写了。
public String execute(){
List list =(List)studentDao.select();
Iterator it = list.iterator();
Student stu = new Student();
//while(it.next()){
// System.out.println(stu.getName());
}
return SUCCESS;
}
其实我的疑问就是怎么把取出来的值在jsp页面中显示出来,在网上查了下有用request.setAtrribute()的,
用struts2的标签该怎么做?各位大大,这个问题困扰我好久!现在处于学习上升期,不要让我打击到

解决方案 »

  1.   

    我的Action改了
    package com.student.action;import java.util.Iterator;
    import java.util.List;
    import java.util.Map;import javax.servlet.http.HttpSession;import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;
    import com.student.Student;
    import com.student.Dao.StudentDao;
    import com.student.Dao.StudentDaoImpl;public class DisplayAction extends ActionSupport{
    private Student student;
    private List myList;
    private StudentDao studentDao = new StudentDaoImpl();
    public Student getStudent() {
    return student;
    }
    public void setStudent(Student student) {
    this.student = student;
    }
    public List getMyList() {
    return myList;
    }
    public void setMyList(List myList) {
    this.myList = myList;
    }
    public String execute(){
    List mylist =(List)studentDao.select();
    this.setMyList(myList);
    return SUCCESS;
    }
    display.jap改了
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
     <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
    <head></head>
     <s:head/>
     
      <body>
      <s:form action="DisplayAction">
        <table>
        <tr>
        <td>id</td>
        <td>姓名</td>
        <td>性别</td>
        <td>生日</td>
        <td>学籍</td>
        </tr>
        <s:iterator value="mylist" status="st">
        <tr>
        <td><s:property value="#st.getId()"/></td>
        <td><s:property value="#st.getName()"/></td>
        <td><s:property value="#st.getSex()"/></td>
        <td><s:property value="#st.getBirthday()"/></td>
        <td><s:property value="#st.getNation()"/></td>
        </tr>
        </s:iterator>
        </table>
        <s:submit value="确定"/>
        </s:form>
      </body>
    </html>
    没结果啊????
      

  2.   


    <s:iterator value="mylist" status="st"> 
        <tr> 
        <td> <s:property value="Id"/> </td> 
        <td> <s:property value="name"/> </td> 
        <td> <s:property value="sex"/> </td> 
        <td> <s:property value="..."/> </td> 
        <td> <s:property value="...."/> </td> 
        </tr> 
        </s:iterator>