知识大全 Struts+hibernate投票系统代码实例

Posted

篇首语:识字粗堪供赋役,不须辛苦慕公卿。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Struts+hibernate投票系统代码实例相关的知识,希望对你有一定的参考价值。

Struts+hibernate投票系统代码实例  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

    本系统采用Struts + Hibernate 作为主题框架        数据库采用Mysql        开源包使用JSTL+JFreeChart        项目结构如下         action        ChartServlet java        VoteAction java        VoteDeleteAction java        VoteEditAction java        VoteitemDeleteAction java        VoteitemEditAction java        VoteitemListAction java        VoteitemSaveAction java        VoteManageAction java        VoteSaveAction java        dao        IVoteDAO java        VoteDAO java        sql        script sql        model        vote hbm xml        voteItem hbm xml        Vote java        Voteitems java        util        DAOFactory java        HibernateDAO java        HibernateFilter java        HibernateUtil java        SelectConst java        VoteFunction java        ChartServlet        package cn hxex vote action;        import java io IOException;        import java util Iterator;        import javax servlet ServletException;        import javax servlet HttpServlet;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import jfree chart ChartFactory;        import jfree chart ChartUtilities;        import jfree chart JFreeChart;        import jfree chart plot PlotOrientation;        import jfree data category DefaultCategoryDataset;        import jfree data general DefaultPieDataset;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        import cn hxex vote util DAOFactory;        public class ChartServlet extends HttpServlet …        /** *//**        * Constructor of the object         */        public ChartServlet() …        super()                 /** *//**        * Destruction of the servlet <br>        */        public void destroy() …        super destroy() // Just puts destroy string in log        // Put your code here                public void doGet(HttpServletRequest request HttpServletResponse response)        throws ServletException IOException …        doPost( request response )                 public void doPost(HttpServletRequest request HttpServletResponse response)        throws ServletException IOException …        String id=request getParameter( id )         IVoteDAO votedao=DAOFactory getVoteDAO()         Vote vote=votedao getVote(id)         JFreeChart chart=getChart(vote)         response setContentType( image/jpeg )         ChartUtilities writeChartAsJPEG(response getOutputStream() chart )                 public static JFreeChart getChart(Vote vote)…        JFreeChart chart=null;        if(vote getPictype() indexOf( PIE )== )…        DefaultPieDataset date=new DefaultPieDataset()         Iterator iter=vote getVoteitems() iterator()         while(iter hasNext())…        Voteitems vi=(Voteitems)iter next()         date setValue(vi getTitle() vi getVotenum())                 if( PIE equals(vote getPictype()))…        chart=ChartFactory createPieChart(vote getTitle() date false false false)         else…        chart=ChartFactory createPieChart D(vote getTitle() date false false false)                 else…        DefaultCategoryDataset date=new DefaultCategoryDataset()         Iterator it=vote getVoteitems() iterator()         while(it hasNext())…        Voteitems vi=(Voteitems)it next()         date addValue(vi getVotenum() 选项 vi getTitle())                 if( BAR equals(vote getPictype()))…        chart=ChartFactory createBarChart(vote getTitle() 选项 数量 date PlotOrientation VERTICAL false false false)                 else…        chart=ChartFactory createBarChart D(vote getTitle() 选项 数量 date PlotOrientation VERTICAL false false false)                         return chart;                public void init() throws ServletException …        // Put your code here                                VoteAction        /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import java util Iterator;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        String id=request getParameter( id )         IVoteDAO voteDao=DAOFactory getVoteDAO()         Vote vote=voteDao getVote(id)         String[] voteitem=request getParameterValues(id)         if(voteitem!=null&voteitem length> )…        for(int i= ;i<voteitem length;i++)…        Iterator iter=vote getVoteitems() iterator()         while(iter hasNext())…        Voteitems vi=(Voteitems)iter next()         if(voteitem[i] equals(vi getId()))…        vi increaseVotenum()         break;                                        request setAttribute( vote vote)         return mapping findForward( success )                   VoteDeleteAction        /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteDeleteAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         Vote vote=voteDao getVote(id)         voteDao deleteVote(vote)         request setAttribute( vote vote)         return mapping findForward( success )                         /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteEditAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         Vote vote=voteDao getVote(id)         request setAttribute( vote vote)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteitemDeleteAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         String voteid=voteDao getVoteItem(id) getVote() getId()         Voteitems voteitem=voteDao getVoteItem(id)         voteDao deleteVoteItem(voteitem)         Vote vote=voteDao getVote(voteid)         vote getVoteitems() remove(voteitem)         request setAttribute( vote vote)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteitemEditAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         Voteitems viforup = voteDao getVoteItem( id )         request setAttribute( viforup viforup )         Vote vote = viforup getVote()         request setAttribute( vote vote )         request setAttribute( vote vote)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteitemListAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         Vote vote=voteDao getVote(id)         request setAttribute( vote vote)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model *;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteitemSaveAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String voteid=request getParameter( voteid )         String id=request getParameter( id )         String title=request getParameter( title )         String votenum=request getParameter( votenum )         Voteitems voteitem=new Voteitems()         Vote vote=voteDao getVote(voteid)         if(id equals( )||id==null)…        voteitem setTitle(title)         voteitem setVotenum(Integer valueOf(votenum))         voteitem setVote(vote)         vote getVoteitems() add(voteitem)         voteDao saveVoteItem(voteitem)         else…        voteitem=voteDao getVoteItem(id)         voteitem setTitle(title)         voteitem setVotenum(Integer valueOf(votenum))         voteitem setVote(vote)         vote getVoteitems() add(voteitem)         voteDao updateVoteItem(voteitem)                 request setAttribute( vote vote)         //request setAttribute( viforup voteitem)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import java util List;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote util DAOFactory;        /** *//**        * MyEclipse Struts        * Creation date:         *        * XDoclet definition:        * @struts action validate= true         */        public class VoteManageAction extends Action …        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         List votes=voteDao getAllVotes()         request setAttribute( votes votes)         return mapping findForward( success )                 /**//*        * Generated by MyEclipse Struts        * Template path: templates/java/JavaClass vtl        */        package cn hxex vote action;        import javax servlet HttpServletRequest;        import javax servlet HttpServletResponse;        import apache struts action Action;        import apache struts action ActionForm;        import apache struts action ActionForward;        import apache struts action ActionMapping;        import cn hxex vote dao IVoteDAO;        import cn hxex vote model Vote;        import cn hxex vote util DAOFactory;        /** *//**                * Creation date:         *        * XDoclet definition:        * @struts action validate= true         * @struts action forward name= success path=         */        public class VoteSaveAction extends Action …        /**//*        * Generated Methods        */        /** *//**        * Method execute        * @param mapping        * @param form        * @param request        * @param response        * @return ActionForward        */        public ActionForward execute(ActionMapping mapping ActionForm form         HttpServletRequest request HttpServletResponse response) …        IVoteDAO voteDao=DAOFactory getVoteDAO()         String id=request getParameter( id )         String name=request getParameter( name )         String title=request getParameter( title )         String votetype=request getParameter( votetype )         String pictype=request getParameter( pictype )         Vote vote=new Vote()         if(id equals( )||id==null)…        vote setId(id)         vote setName(name)         vote setTitle(title)         vote setVotetype(votetype)         vote setPictype(pictype)         voteDao saveVote(vote)                 else        …        vote=voteDao getVote(id)         vote setName(name)         vote setTitle(title)         vote setVotetype(votetype)         vote setPictype(pictype)         voteDao updateVote(vote)                 request setAttribute( vote vote)         return mapping findForward( success )                 package cn hxex vote dao;        import java util List;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        public interface IVoteDAO …        public void saveVote(Vote vote)         public void saveVoteItem(Voteitems voteitem)         public void updateVote(Vote vote)         public void updateVoteItem(Voteitems voteitem)         public void deleteVote(Vote vote)         public void deleteVoteItem(Voteitems voteitem)         public Vote getVote(String id)         public Vote getVoteByName(String name)         public List getAllVotes()         public Voteitems getVoteItem(String id)                 package cn hxex vote dao;        import java util List;        import cn hxex vote model Vote;        import cn hxex vote model Voteitems;        import cn hxex vote util HibernateDAO;        public class VoteDAO extends HibernateDAO implements IVoteDAO …        public void deleteVote(Vote vote) …        super deleteObject(vote)                 public void deleteVoteItem(Voteitems voteitem) …        super deleteObject(voteitem)                 public List getAllVotes() …        String hql= from Vote ;        return super getObjects(hql)                 public Vote getVote(String id) …        return (Vote)super getObject(Vote class id)                 public Vote getVoteByName(String name) …        String hql= from Vote where name= +name+ ;        return (Vote)super getObject(hql)                 public Voteitems getVoteItem(String id) …        return (Voteitems)super getObject(Voteitems class id)                 public void saveVote(Vote vote) …        super saveObject(vote)                 public void saveVoteItem(Voteitems voteitem) …        super saveObject(voteitem)                 public void updateVote(Vote vote) …        super updateObject(vote)                 public void updateVoteItem(Voteitems voteitem) …        super updateObject(voteitem)                         <?xml version= ?>        <!DOCTYPE hibernate mapping PUBLIC        //Hibernate/Hibernate Mapping DTD //EN         mapping dtd >        <hibernate mapping package= cn hxex vote model >        <class name= Vote table= vote >        <id name= id column= id type= string >        <generator class= uuid hex ></generator>        </id>        <property name= name column= name >        </property>        <property name= title column= title >        </property>        <property name= votetype column= votetype >        </property>        <property name= pictype column= pictype >        </property>        <set name= voteitems cascade= delete order by= title asc inverse= true >        <key column= vote_id ></key>        <one to many class= Voteitems />        </set>        </class>        </hibernate mapping>        <?xml version= ?>        <!DOCTYPE hibernate mapping PUBLIC        //Hibernate/Hibernate Mapping DTD //EN         mapping dtd >        <hibernate mapping package= cn hxex vote model >        <class name= Voteitems table= voteitem >        <id name= id column= id type= string >        <generator class= uuid hex ></generator>        </id>        <property name= title column= title >        </property>        <property name= votenum column= votenum >        </property>        <many to one name= vote column= vote_id ></many to one>        </class>        </hibernate mapping>        package cn hxex vote model;        import java util Set;        public class Vote …        private String id;        private String name;        private String title;        private String votetype;        private String pictype;        private Set voteitems;        public String getId() …        return id;                public void setId(String id) …        this id = id;                public String getName() …        return name;                public void setName(String name) …        this name = name;                public String getPictype() …        return pictype;                public void setPictype(String pictype) …        this pictype = pictype;                public String getTitle() …        return title;                public void setTitle(String title) …        this title = title;                public Set getVoteitems() …        return voteitems;                public void setVoteitems(Set voteitems) …        this voteitems = voteitems;                public String getVotetype() …        return votetype;                public void setVotetype(String votetype) …        this votetype = votetype;                        package cn hxex vote model;        public class Voteitems …        private String id;        private String title;        private Integer votenum;        private Vote vote;        public String getId() …        return id;                public void setId(String id) …        this id = id;                public String getTitle() …        return title;                public void setTitle(String title) …        this title = title;                public Vote getVote() …        return vote;                public void setVote(Vote vote) …        this vote = vote;                public Integer getVotenum() …        return votenum;                public void setVotenum(Integer votenum) …        this votenum = votenum;                public void increaseVotenum()…        int num=getVotenum() intValue()+ ;        setVotenum(new Integer(num))                         CREATE TABLE `vote` (        `id` varchar( ) NOT NULL default         `name` varchar( ) default NULL         `title` varchar( ) default NULL         `votetype` varchar( ) default NULL         `pictype` varchar( ) default NULL         PRIMARY KEY  (`id`)        ) ENGINE=InnoDB DEFAULT CHARSET=gb ROW_FORMAT=REDUNDANT;        CREATE TABLE `voteitem` (        `id` varchar( ) NOT NULL default         `title` varchar( ) default NULL         `votenum` varchar( ) default NULL         `vote_id` varchar( ) NOT NULL         PRIMARY KEY  (`id`)         KEY `fk_vote_no` (`vote_id`)         ) ENGINE=InnoDB DEFAULT CHARSET=gb ROW_FORMAT=REDUNDANT;        package cn hxex vote util;        import cn hxex vote dao IVoteDAO;        public class DAOFactory …        public static IVoteDAO getVoteDAO()…        return (IVoteDAO)getInstance( cn hxex vote dao VoteDAO )                 static Object getInstance(String className)…        try …        Class cls=Class forName(className)         return cls newInstance()         catch (Exception e) …        e printStackTrace()         return null;                                package cn hxex vote util;        import java util List;        import hibernate Session;        public class HibernateDAO …        public void saveObject(Object obj)…        getSession() save(obj)                 public void updateObject(Object obj)…        getSession() update(obj)                 public List getObjects(String hql)…        List result=getSession() createQuery(hql) list()         return result;                public Object getObject(String hql)…        Object result=getSession() createQuery(hql) uniqueResult()         return result;                public Object getObject(Class cls String id)…        return getSession() get(cls id)                 public void deleteObject(Object obj)…        getSession() delete(obj)                 protected Session getSession()…        return HibernateUtil getSessionFactory() getCurrentSession()                         package cn hxex vote util;        import java io IOException;        import javax servlet Filter;        import javax servlet FilterChain;        import javax servlet FilterConfig;        import javax servlet ServletException;        import javax servlet ServletRequest;        import javax servlet ServletResponse;        import javax servlet HttpServletRequest;        import mons logging Log;        import mons logging LogFactory;        import hibernate SessionFactory;        import cn hxex vote util HibernateUtil;        /** *//**        * 用于进行Hibernate事务处理的Servlet过滤器        *        * @author galaxy        */        public class HibernateFilter implements Filter …        private static Log log = LogFactory getLog(HibernateFilter class)         /** *//**        * 过滤器的主要方法        * 用于实现Hibernate事务的开始和提交        */        public void doFilter(ServletRequest request         ServletResponse response         FilterChain chain)        throws IOException ServletException        …        // 得到SessionFactory对象的实例        SessionFactory sf = HibernateUtil getSessionFactory()         try        …        // 开始一个新的事务        log debug( Starting a database transaction )         sf getCurrentSession() beginTransaction()         log debug( Request Path: + ((HttpServletRequest)request) getServletPath() )         // 设置用户请求的编码格式        request setCharacterEncoding( gb )         // Call the next filter (continue request processing)        chain doFilter(request response)         // 提交事务        log debug( Committing the database transaction )         sf getCurrentSession() getTransaction() mit()                 catch (Throwable ex)        …        ex printStackTrace()         try        …        // 会滚事务        log debug( Trying to rollback database transaction after exception )         sf getCurrentSession() getTransaction() rollback()                 catch (Throwable rbEx)        …        log error( Could not rollback transaction after exception! rbEx)                 // 抛出异常        throw new ServletException(ex)                         /** *//**        * Servlet过滤器的初始化方法        * 可以读取配置文件中设置的配置参数        */        public void init(FilterConfig filterConfig) throws ServletException …        /** *//**        * Servlet的销毁方法        * 用于释放过滤器所申请的资源        */        public void destroy() …        package cn hxex vote util;        import javax naming InitialContext;        import javax naming NamingException;        import mons logging Log;        import mons logging LogFactory;        import hibernate Interceptor;        import hibernate SessionFactory;        import hibernate cfg Configuration;        import hibernate cfg Environment;        /** *//**        * 基础的Hibernate辅助类 用于Hibernate的配置和启动         * <p>        * 通过静态的初始化代码来读取Hibernate启动参数 并初始化        * <tt>Configuration</tt>和<tt>SessionFactory</tt>对象         * <p>        *        * @author galaxy        */        public class HibernateUtil        …        private static Log log = LogFactory getLog(HibernateUtil class)         // 指定定义******属性名        private static final String INTERCEPTOR_CLASS = hibernate util interceptor_class ;        // 静态Configuration和SessionFactory对象的实例(全局唯一的)        private static Configuration configuration;        private static SessionFactory sessionFactory;        static        …        // 从缺省的配置文件创建SessionFactory        try        …        // 创建默认的Configuration对象的实例        // 如果你不使用JDK 或者注释请使用new Configuration()        // 来创建Configuration()对象的实例        configuration = new Configuration()         // 读取hibernate properties或者hibernate cfg xml文件        nfigure()         // 如果在配置文件中配置了****** 那么将其设置到configuration对象中        String interceptorName = configuration getProperty(INTERCEPTOR_CLASS)         if (interceptorName != null)        …        Class interceptorClass =        HibernateUtil class getClassLoader() loadClass(interceptorName)         Interceptor interceptor = (Interceptor)interceptorClass newInstance()         configuration setInterceptor(interceptor)                 if (configuration getProperty(Environment SESSION_FACTORY_NAME) != null)        …        // 让Hibernate将SessionFacory绑定到JNDI        configuration buildSessionFactory()                 else        …        // 使用静态变量来保持SessioFactory对象的实例        sessionFactory = configuration buildSessionFactory()                         catch (Throwable ex)        …        // 输出异常信息        log error( Building SessionFactory failed ex)         ex printStackTrace()         throw new ExceptionInInitializerError(ex)                         /** *//**        * 返回原始的Configuration对象的实例        *        * @return Configuration        */        public static Configuration getConfiguration()        …        return configuration;                /** *//**        * 返回全局的SessionFactory对象的实例        *        * @return SessionFactory        */        public static SessionFactory getSessionFactory()        …        SessionFactory sf = null;        String sfName = configuration getProperty(Environment SESSION_FACTORY_NAME)         if ( sfName != null)        …        log debug( Looking up SessionFactory in JNDI )         try        …        sf = (SessionFactory) new InitialContext() lookup(sfName)                 catch (NamingException ex)        …        throw new RuntimeException(ex)                         else        …        sf = sessionFactory;                if (sf == null)        throw new IllegalStateException( SessionFactory not available )         return sf;                /** *//**        * 关闭当前的SessionFactory并且释放所有的资源        */        public static void shutdown()        …        log debug( Shutting down Hibernate )         // Close caches and connection pools        getSessionFactory() close()         // Clear static variables        configuration = null;        sessionFactory = null;                /** *//**        * 使用静态的Configuration对象来重新构建SessionFactory         */        public static void rebuildSessionFactory()        …        log debug( Using current Configuration for rebuild )         rebuildSessionFactory(configuration)                 /** *//**        * 使用指定的Configuration对象来重新构建SessionFactory对象         *        * @param cfg        */        public static void rebuildSessionFactory(Configuration cfg)        …        log debug( Rebuilding the SessionFactory from given Configuration )         synchronized(sessionFactory)        …        if (sessionFactory != null && !sessionFactory isClosed())        sessionFactory close()         if (cfg getProperty(Environment SESSION_FACTORY_NAME) != null)        cfg buildSessionFactory()         else        sessionFactory = cfg buildSessionFactory()         configuration = cfg;           

相关参考

知识大全 浅谈Struts2分页的实现与代码实例

浅谈Struts2分页的实现与代码实例  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  关于Str

知识大全 struts框架中使用tiles组件代码实例

   在你的struts配置文件strutsconfigxml中加入下面的配置      <plugin

知识大全 Struts处方:Hibernate与Struts

Struts处方:Hibernate与Struts  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 struts标签+jstl标签之国际化实例

  Struts提供了国际化的功能对于一个面向各国的系统来说是非常有帮助的只需要提供每个国家的语言资源包配置后即可使用  下面来用一个登录实例来演示一下Struts的国际化配置和显示  创建一个log

知识大全 Struts+Spring+Hibernate快速入门

Struts+Spring+Hibernate快速入门  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧

知识大全 Struts&Spring&Hibernate面试总结

Struts&Spring&Hibernate面试总结  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧

知识大全 Struts 2, spring 2, hibernate

Struts2,spring2,hibernate  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 js实时获取系统当前时间实例代码

在网页中实时的显示时间不但可以给网页添色还可以方便浏览者掌握当前时间为了提高网站的开发速度可以把主代码封装在一个单独的函数里面在需要的时候直接调用而我为了演示直接写在了主页面方便大家观看  

知识大全 MyEclipse+struts+Hibernate配置开发手册

MyEclipse+struts+Hibernate配置开发手册  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起

知识大全 struts2 + spring + hibernate&

   struts释出已经很久了虽然自己现在作GUI开发不过有时间还是学习下web开发现在就将我使用myeclipse工具应用struts+spring+hibernat