第四個文件
import net
import net
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration()
} catch (HibernateException ex) {
throw new RuntimeException(
+ ex
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
// Session s;
Session s = (Session) session
// Open a new Session
if (s == null) {
s = sessionFactory
session
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session
session
if (s != null)
s
}
}
第五個文件
<%@ page contentType=
<%@ page import=
<html>
<head>
<title>test</title>
</head>
<body bgcolor=
<h
<a href=
<%
if(request
String name = request
if(name == null || name
out
return;
}
SessionFactory sessionFactory;
net
Transaction tx = hsession
[
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29029.html