JAVAEE课程设计图书馆里系统(6)

2019-08-29 23:41

/**

* Location of hibernate.cfg.xml file.

* Location should be on the classpath as Hibernate uses

* #resourceAsStream style lookup for its configuration file.

* The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update

* the location of the configuration file for the current session. */

private static String CONFIG_FILE_LOCATION = \ private static final ThreadLocal threadLocal = new ThreadLocal();

private static Configuration configuration = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; private static String configFile = CONFIG_FILE_LOCATION;

static { try {

configuration.configure(configFile);

sessionFactory = configuration.buildSessionFactory(); } catch (Exception e) { System.err

.println(\ e.printStackTrace(); } }

private HibernateUtil() { } /**

* Returns the ThreadLocal Session instance. Lazy initialize * the SessionFactory if needed. *

* @return Session

* @throws HibernateException */

public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); }

session = (sessionFactory != null) ? sessionFactory.openSession() : null;

threadLocal.set(session);

24

}

return session; }

/**

* Rebuild hibernate session factory * */

public static void rebuildSessionFactory() { try {

configuration.configure(configFile);

sessionFactory = configuration.buildSessionFactory(); } catch (Exception e) { System.err

.println(\ e.printStackTrace(); } }

/**

* 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(); } }

/**

* return session factory * */

public static org.hibernate.SessionFactory getSessionFactory() { return sessionFactory; }

/**

* return session factory *

25

* session factory will be rebuilded in the next call */

public static void setConfigFile(String configFile) { HibernateUtil.configFile = configFile; sessionFactory = null; }

/**

* return hibernate configuration * */

public static Configuration getConfiguration() { return configuration; } }

Struts.xml

\ \>

/main.jsp /error.jsp /login.jsp /login.jsp

class=\ method=\> /booktype_add.jsp /booktype_add.jsp /message.jsp

26

/error.jsp

/booktype_query_result.jsp /booktype_modify.jsp

/book_add.jsp /book_add.jsp

/message.jsp /message.jsp /message.jsp /error.jsp

/book_query_result.jsp /book_modify.jsp

class=\>

/message.jsp /error.jsp

/user_query_result.jsp /message.jsp /error.jsp

27

五、系统测试

5-1 添加图书类别成功

输入所要添加的管理员名称,然后输入密码,再次确认密码,点击添加,显示添加管理员成功。

28


JAVAEE课程设计图书馆里系统(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:法律文化节开幕式 修改版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: