StudentDao类: package com.dao; /*import java.util.ArrayList; import java.util.List;*/ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; /*import org.hibernate.query.Query;*/ import com.student.Student; public class StudentDao { public Student getById(int id){ Configuration cfg=new Configuration().configure(); SessionFactory sessionFactory=cfg.buildSessionFactory(); Session session=sessionFactory.openSession(); Transaction tran=session.beginTransaction(); Student s=session.get(Student.class, id); tran.commit(); session.close(); return s; } } jsp代码: <% StudentDao dao=new StudentDao(); Student s=dao.getById(13); %> <table> <tr> <td><%=s.getName() %></td> <td><%=s.getNumber() %></td> <td><%=s.getBirthday() %></td> </tr> 提示Configuration cfg=new Configuration().configure();这一行代码有错,可是我写的测试类可以成功过去s,在jsp页面中调用 就有错,类已经导入了,数据库也有数据,是运行时的错误。
hibernate2.5是不用Configure创建对象的
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="pojo.Students"%> <%@page import="test.StudentTest"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <%! StudentTest studentTest=new StudentTest(); Students s=studentTest.test(); %> <title>Test</title> </head> <body> <label><%=s.getSid() %></label> <label><%=s.getSname() %></label> <label><%=s.getGender() %></label> <label><%=s.getBirthday() %></label> <label><%=s.getAddress() %></label> </body> </html>
lib下引入包,jsp文件中引入java类,数据库中要有数据。。。。
什么错误?你倒是贴出来呀