采用了基于Spring + Struts +Hibernate框架
利用数据库mysql辅助数据存储功能
部分代码如下
/ import javax.servlet.ServletRequest;
/
/ import javax.servlet.ServletResponse;
/
/ import javax.servlet.http.HttpServletRequest;
/
/ import org.apache.commons.logging.Log;
/
/ import org.apache.commons.logging.LogFactory;
/
/ import org.hibernate.Session;
/
/ import org.hibernate.Transaction;
/
/
/
/ public class HibernateFilter
/
/ implements Filter
/
/ {
/
21 / public static Log log = LogFactory.getLog(HibernateFilter.class);
/
/
/
/ public void destroy()
/
/ {
/
/ }
/
/
/
/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
/
/ {
/
29 / Session session = HibernateSessionFactory.getSession();
/
/ try {
/
31 / log.debug(“set character Encoding to GBK”);
/
32 / request.setCharacterEncoding(“GBK”);
/
33 / log.debug(“starting a database transation”);
/
34 / session.beginTransaction();
/
/
/
36 / log.debug(“Request path:\t” +
/
37 / ((HttpServletRequest)request).getServletPath());
/
38 / chain.doFilter(request, response);
/
39 / log.debug(“Committing the database transaction after exception.”);
/
40 / session.getTransaction().commit();
/
/ } catch (Throwable ex) {
/
42 / ex.printStackTrace();
/
/ try {
/
44 / log.debug(“Trying to roolback database transaction after exception.”);
/
45 / session.getTransaction().rollback();
/
/ }
/
/ catch (Throwable rbEx)
/
/ {
/
49 / log.error(“Could not roolback transaction after exception!”, rbEx);
/
/ }
/
51 / throw new ServletException(ex);
/
/ }
/
/ }
/
/
/
/ public void init(FilterConfig arg0)
/
/ throws ServletException
/
/ {
/
/ }
/
*/ }

/* / package cn.lee.market.util;
/
/
/
/ import java.io.PrintStream;
/
/ import org.hibernate.HibernateException;
/
/ import org.hibernate.Session;
/
/ import org.hibernate.SessionFactory;
/
/ import org.hibernate.cfg.Configuration;
/
/
/
/ public class HibernateSessionFactory
/
/ {
/
22 / private static String CONFIG_FILE_LOCATION = “/hibernate.cfg.xml”;
/
23 / private static final ThreadLocal threadLocal = new ThreadLocal();
/
24 / private static Configuration configuration = new Configuration();
/
/ private static SessionFactory sessionFactory;
/
26 / private static String configFile = CONFIG_FILE_LOCATION;
/
/
/
/ public static Session getSession()
/
/ throws HibernateException
/
/ {
/
39 / Session session = (Session)threadLocal.get();
/
/
/
41 / if ((session == null) || (!session.isOpen())) {
/
42 / if (sessionFactory == null) {
/
43 / rebuildSessionFactory();
/
/ }
/
45 / session = sessionFactory != null ? sessionFactory.openSession() :
/
46 / null;
/
47 / threadLocal.set(session);
/
/ }
/
/
/
50 / return session;
/
/ }
/
/
/
/ public static void rebuildSessionFactory()
/
/ {
/
/ try
/
/ {
/
59 / configuration.configure(configFile);
/
60 / sessionFactory = configuration.buildSessionFactory();
/
/ } catch (Exception e) {
/
62 / System.err
/
63 / .println("%%%% Error Creating SessionFactory %%%%");
/
64 / e.printStackTrace();
/
/ }
/
/ }
/
/
/
/ public static void closeSession()
/
/ throws HibernateException
/
/ {
/
74 / Session session = (Session)threadLocal.get();
/
75 / threadLocal.set(null);
/
/
/
77 / if (session != null)
/
78 / session.close();
/
/ }
/
/
/
/ public static SessionFactory getSessionFactory()
/
/ {
/
87 / return sessionFactory;
/
/ }
/
/
/
/ public static void setConfigFile(String configFile)
/
/ {
/
96 / configFile = configFile;
/
97 / sessionFactory = null;
/
/ }
/
/
/
/ public static Configuration getConfiguration()
/
/ {
/
105 / return configuration;
/
/ }
/
*/ }

/* Location: C:\Users\muye\Desktop\51\校园二手交易平台设计\market\code\market\WEB-INF\classes\

  • Qualified Name: cn.lee.market.util.HibernateSessionFactory
  • JD-Core Version: 0.6.1
    */
    实现截图
    基于ssh的校园二手平台项目
    基于ssh的校园二手平台项目
    基于ssh的校园二手平台项目

相关文章: