为了更好的演示我们不建立通常的登陆页面而是建立个注册页面。选择 src目录下的hibernate.cfg.xml文件。照如下填写并保存。这样hibernate就为你建立了数据库的连接池。

下面我们再选择WebRoot/WEB-INF/struts-config.xml文件,在画面中点击右键选择new- >Form, Action and JSP。如下填写

再选择JSP选项,如下

最后选择Finish。
再新建一个一个success.jsp的页面,
在刚才struts- config.xml文件里右键选择addAdmin选择Properties,在菜单里选择Forwords,再点add,如下图填写

最后你的struts-config.xml就是下面这个样子:

下面我们转到hibernate。换到刚才我们建立数据库的页面,选择你的admin的表点右键选择Create Hibernate Mapping。选择好打包路径后选择Finish。如图:

在你刚才选择的路径下(我为方便是src/com/yourcompanyname/)下新建立的文件 AdminDAOFactory.java文件并输入以下内容:
package com.yourcompanyname;
import java.util.Iterator;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.hibernate.SessionFactory;
public class AdminDAOFactory {
Session session;
Transaction tx;
public void add(Admin admin) throws HibernateException {
/**
* Creation Date: 11-17-2005
* TODO Add a new admin user.
* @param An object of Admin
* @return void
* @author Coder Guo
*/
try {
session = SessionFactory.currentSession();
tx = session.beginTransaction();
//Add a new admin
session.save(admin);
tx.commit ();
}catch(HibernateException e){
throw e;
}finally{
if (tx!=null) {
tx.rollback();
}
SessionFactory.closeSession();
}
}
}