日期:2014-05-17  浏览次数:20709 次

s2h整合,从数据库读数据通过jsp显示,总是出错!!
从student表取出数据,HibernateUtil类已经拿到SessionFactory
	public static List<Student> list() {
List<Student> students = new ArrayList<Student>();
String hql = "from Student";

Session session = HibernateUtil.getSession();
session.beginTransaction();
Query query = session.createQuery(hql);
students = (List<Student>)query.list();
session.getTransaction().commit();
return students;
}



StudentAction代码
public class StudentAction extends ActionSupport {
private Student student;
private List<Student> students;
private int id;

public Student getStudent() {
return student;
}

public void setStudent(Student student) {
this.student = student;
}

public List<Student> getStudents() {
return students;
}

public void setStudents(List<Student> students) {
this.students = students;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

        public List<Student> list() {
students = DBStudent.list();
return students;
}

public String add() {
DBStudent.save(student);
return SUCCESS;
}

public String loadStudent() {
DBStudent.getStudentById(id);
return SUCCESS;
}

public String update() {
Student s = DBStudent.getStudentById(id);
s = student;
DBStudent.update(s);
return SUCCESS;
}

public String delete() {
Student s = DBStudent.getStudentById(id);
DBStudent.delete(s);
return SUCCESS;
}

public String addInput() {
return INPUT;
}

public String updateInput() {
return INPUT;
}


struts.xml配置文件
<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="GBK"/>
    <package name="default" namespace="/" extends="struts-default">
        <action name="*_Student" class="com.iman.StudentInfo.action.StudentAction" method="{1}">
            <result>/main.jsp</result>
            <result name="input">/add.jsp</result>
        </action>

    </package>

&n