it167.com  设为主页
 收藏本站
 
  资讯:业界动态 | 软件动态 | 人物专栏 | 安全资讯 | 网络生活 | 电子商务 | 小游戏 | 视频 | 美女图片 | 音乐
  网络编程 | 网站运营 | 网页制作 | 图形图象 | 操作系统 | 媒体动画 | 软件教学 | 网络应用 | 邮件系统 | 网络安全 | 认证考试
asp | .net | php | jsp | Sql | java | Dreamweaver | FrontPages | Javascript | css | Coreldraw | photoshop | Flash | Coreldraw
当前位置: > 主页>网络编程>Java>JAVA开发技巧>Struts+hibernate开发(源代码)(1)
最新新闻

·机会与整合 边缘化互联
·TOM-Skype新增三大本地
·雅虎抢闸邮箱竞赛 网易
·新浪抢攻北京奥运
·洞悉网络口碑的掘金机会
·拆解网络病毒黑金交易
·木马下载器近期出现新变
·《互联网周刊》第17期文
·Web2.0是否催生自吹自擂
·三张宝宝裸照招来MSN封
热门新闻
·Java SE 6 的HTTP 协议
·Java中对HashMap的深度
·Java调用Oracle的过程和
·开源技术 Eclipse使用技
·深入了解WebLogic的类装
·Java进阶:Struts多模块
·Java初学者入门经典:面
·Jave学习精华:Jsp小结
·Java学习:EJB的专用术语
·编程必备经典:Java常见
推荐新闻
 
 

Struts+hibernate开发(源代码)(1) 

作者:   来源:it167   点击:   日期:2007-01-28

UserForm.java

//Created by MyEclipse Struts

// XSL source (default):

platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xsl

package form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

/**

* MyEclipse Struts

* Creation date: 03-25-2006

*

* XDoclet definition:

* @struts.form name="userForm"

*/

public class UserForm extends ActionForm {

// --------------------------------------------------------- Instance Variables

/** password property */

private String password;

/** name property */

private String name;

// --------------------------------------------------------- Methods

/**

* Method validate

* @param mapping

* @param request

* @return ActionErrors

*/

public ActionErrors validate(

ActionMapping mapping,

HttpServletRequest request) {

// TODO Auto-generated method stub

return null;

}

/**

* Method reset

* @param mapping

* @param request

*/

public void reset(ActionMapping mapping, HttpServletRequest request) {

// TODO Auto-generated method stub

}

/**

* Returns the password.

* @return String

*/

public String getPassword() {

return password;

}

/**

* Set the password.

* @param password The password to set

*/

public void setPassword(String password) {

this.password = password;

}

/**

* Returns the name.

* @return String

*/

public String getName() {

return name;

}

/**

* Set the name.

* @param name The name to set

*/

public void setName(String name) {

this.name = name;

}

}

HibernateSessionFactory.java

package hibernate;

import org.hibernate.HibernateException;

import org.hibernate.Session;

import org.hibernate.cfg.Configuration;

/**

* Configures and provides access to Hibernate sessions, tied to the

* current thread of execution. Follows the Thread Local Session

* pattern, see {@link http://hibernate.org/42.html}.

*/

public class HibernateSessionFactory {

/**

* Location of hibernate.cfg.xml file.

* NOTICE: Location should be on the classpath as Hibernate uses

* #resourceAsStream style lookup for its configuration file. That

* is place the config file in a Java package - the default location

* is the default Java package.

* Examples:

* CONFIG_FILE_LOCATION = "/hibernate.conf.xml".

* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".


*/

private static String CONFIG_FILE_LOCATION = "/hibernate/hibernate.cfg.xml";

/** Holds a single instance of Session */

private static final ThreadLocal threadLocal = new ThreadLocal();

/** The single instance of hibernate configuration */

private static final Configuration cfg = new Configuration();

/** The single instance of hibernate SessionFactory */

private static org.hibernate.SessionFactory sessionFactory;

/**

* Returns the ThreadLocal Session instance. Lazy initialize

* the SessionFactory if needed.

*

* @return Session

* @throws HibernateException

*/

public static Session currentSession() throws HibernateException {

Session session = (Session) threadLocal.get();

if (session == null) {

if (sessionFactory == null) {

try {

cfg.configure(CONFIG_FILE_LOCATION);

sessionFactory = cfg.buildSessionFactory();

}

catch (Exception e) {

System.err.println("%%%% Error Creating SessionFactory %%%%");

e.printStackTrace();

}

}

session = sessionFactory.openSession();

threadLocal.set(session);

}

return session;

}

/**

* Close the single hibernate session instance.

*

* @throws HibernateException

*/

public static void closeSession() throws HibernateException {

Session session = (Session) threadLocal.get();

threadLocal.set(null);

if (session != null) {

session.close();

}

}

/**

* Default constructor.

*/

private HibernateSessionFactory() {

}

}



共5页: 上一页 [1] 2 [3] [4] [5] 下一页
文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·设计模式在EJB中的应用 ·让JavaME程序真正Run Anywhere
·利用实体EJB来避免性能缺陷 ·NetBeans 6 M8发布 新添UML建模工具
·Java高手谈论Hibernate的发展之路 ·优化entity Bean的七条准则

   文章评论:(0条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:it167  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。