---
title: "hibernate在tomcat5.5下成功！"
author: "voff12"
date: "2007-01-19T23:23:38Z"
tags: []
slug: "hibernate-tomcat5-5"
draft: false
lastmod: "2007-01-19T23:23:38Z"
id: 48635
url: "https://voff12.iteye.com/blog/48635"
---

```
<%@ page language="java" contentType="text/html;charset=GB2312"%> 
<%@ page import="org.hibernate.*,org.hibernate.cfg.*,ch03.hibernate.HibernateUtil,ch03.hibernate.User"%>

  
   <%
          try{
         Session ssession;
            ssession = HibernateUtil.currentSession();
            Transaction tx= ssession.beginTransaction();
			for(int i=0;i<20;i++){
           	User user = new User();
			
			user.setUsername("Hibernate");
			user.setPassword("hello110");
			user.setEmail("chen@163.com");
            ssession.save(user);
            }
            tx.commit();
			out.println("ok");
 
            HibernateUtil.closeSession();
            }catch(HibernateException e){
            }
            


     
   %> 
```

测试页面。
总结：
1）配置好Context.xml放至META-INF下。tomcat5.5下不同于以前。
2）hibernate.cfg.xml的配置只用一个简单的。
 <property name="connection.datasource">java:comp/env/jdbc/chen</property>即行。测试。
3）编写HibernateUtil类，做为初如化类。
4）要加hibernate的包类加载到WEB-INF/lib下，才能正常使用。
备注：
1)在tomcat下能运行，并不意味可以在java Test能运行。（待检验）