国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Struts Spring Hibernate整合
  1. Struts+Spring+Hibernate    
  2. 本次配置環(huán)境:Myeclipse5.5、MySQL5.0、Struts1.2、Spring2.0、Hibernate3.1    
  3. 一、建工程    
  4. 略。。。。。。    
  5. 二、要使用Struts、Spring、Hibernate必須導(dǎo)入必需的包    
  6. 1、Struts(和之前沒區(qū)別)    
  7. 2、Spring    
  8.    分別導(dǎo)入Spring 2.0 Core Libraries、Spring 2.0 Web Libraries    
  9.    選擇把*.jar Copy到工程/WebRoot/WEB-INF/lib下; 點(diǎn)擊NEXT    
  10.    選擇applicationContext.xml的目錄,/WebRoot/WEB-INF;點(diǎn)擊finish    
  11. 3、Hibernate    
  12.    在導(dǎo)入Hibernate時(shí),當(dāng)然先要配置DataSource咯,這里就不再說了    
  13.    選擇導(dǎo)入Hibernate全選上    
  14.    選上復(fù)選框:Hibernate 3.1 Core......、Hibernate 3.1 Advanced......、Spring 2.0 ORM/DAO.......    
  15.    同樣選擇把*.jar Copy到工程/WebRoot/WEB-INF/lib下; 點(diǎn)擊NEXT    
  16.    這里我們選擇把hibernate交給spring去管理    
  17. 選中單選按鈕 Spring configuration file...... 點(diǎn)擊NEXT    
  18.    選擇已存在的applicationContext.xml文件,    
  19.    填寫SessionFactory ID :sessionFactory 點(diǎn)擊NEXT    
  20.    這里我們需要填寫B(tài)ean Id :dataSource    
  21.    選擇 DB Driver :選擇剛才配置的DataSource 點(diǎn)擊NEXT    
  22.    這里不需要?jiǎng)?chuàng)建 SessionFactory Class 點(diǎn)擊Finish    
  23.    注意:查看applicationContext.xml的變化    
  24. 三、映射VO、數(shù)據(jù)操作    
  25. 首先工程的結(jié)構(gòu)建好,比較簡單的結(jié)構(gòu):    
  26. org.chenwj.dao    
  27. org.chenwj.struts    
  28. org.chenwj.struts.action    
  29. org.chenwj.struts.form    
  30. org.chenwj.vo    
  31. 映射表userinfo創(chuàng)建持久類到org.chenwj.vo目錄    
  32. 在dao下創(chuàng)建數(shù)據(jù)庫操作類 UserDAO 這里只是對(duì)數(shù)據(jù)庫進(jìn)去插入,代碼如下:    
  33. private SessionFactory sessionFactory;    
  34.   
  35.     public SessionFactory getSessionFactory() {    
  36.        return sessionFactory;    
  37.     }    
  38.     public void setSessionFactory(SessionFactory sessionFactory) {    
  39.        this.sessionFactory = sessionFactory;    
  40.     }    
  41.     /* 用戶注冊(cè) */    
  42.     public boolean regist(Userinfo user) {    
  43.        try {    
  44.            Session session = sessionFactory.openSession();    
  45.            Transaction tx = session.beginTransaction();    
  46.            session.save(user);    
  47.            tx.commit();    
  48.            session.close();    
  49.            return true;    
  50.        } catch (Exception ex) {    
  51.            ex.printStackTrace();    
  52.            return false;    
  53.               }    
  54.        }    
  55.     使用依賴注入,setter設(shè)值 sessionFactory    
  56.     到此數(shù)據(jù)層已經(jīng)完成    
  57.       
  58. 四、配置struts-config.xml    
  59.     添加action、form、jsp 略……    
  60.     首先在struts-config.xml添加一個(gè)插件    
  61.     <plug-in    
  62.     className="org.springframework.web.struts.ContextLoaderPlugIn">    
  63.        <set-property property="contextConfigLocation"    
  64.            value="/WEB-INF/applicationContext.xml" />    
  65.     </plug-in>    
  66.     為什么要添回這個(gè)插件呢?    
  67.     因?yàn)樵诤竺鏁?huì)在applicationContext.xml下配置action,讓action交給spring    
  68.     去管理,實(shí)現(xiàn)了struts的依賴注入機(jī)制    
  69.     接下來添加cuntroller,這里你可以使用DelegatingActionProxy代理    
  70.     <controller processorClass=    
  71.     "org.springframework.web.struts.DelegatingRequestProcessor"/>    
  72.     Controller取代了struts的RequestProcessor,在定義action里,我們可以省略    
  73. type屬性。(我個(gè)人比較喜歡用這個(gè))下面讓我們看配置好的struts-config.xml:    
  74. <struts-config>    
  75.         <data-sources />    
  76.         <form-beans>    
  77.            <form-bean name="userForm"    
  78.            type="org.chenwj.struts.form.UserForm" />    
  79.         </form-beans>    
  80.     <global-exceptions />    
  81.     <global-forwards />    
  82.     <action-mappings>    
  83.        <action attribute="userForm" input="/index.jsp" name="userForm"    
  84.            path="/user" scope="request">    
  85.            <forward name="success" path="/success.jsp" />    
  86.            <forward name="error" path="/index.jsp" />    
  87.        </action><!--type屬性可不寫-->    
  88.     </action-mappings>    
  89.   
  90.     <controller processorClass=    
  91. "org.springframework.web.struts.DelegatingRequestProcessor"/>    
  92.   
  93.      <message-resources    
  94.        parameter="org.chenwj.struts.ApplicationResources" />    
  95.      <plug-in    
  96.     className="org.springframework.web.struts.ContextLoaderPlugIn">    
  97.        <set-property property="contextConfigLocation"    
  98.            value="/WEB-INF/applicationContext.xml" />    
  99.      </plug-in>    
  100. </struts-config>    
  101.   
  102. 五、在applicationContext.xml配置action    
  103.     這里我們先在 action類里添加一些業(yè)務(wù)邏輯,代碼如下:    
  104.     public class UserAction extends Action {    
  105.   
  106.     private UserDAO userDao;    
  107.     private Userinfo user;    
  108.   
  109.     public ActionForward execute(ActionMapping mapping, ActionForm form,    
  110.        HttpServletRequest request, HttpServletResponse response) {    
  111.    UserForm userForm = (UserForm) form;    
  112.    //封裝數(shù)據(jù)    
  113.    user.setName(userForm.getName());    
  114.        user.setPassword(userForm.getPassword());    
  115.        if(userDao.regist(user)){    
  116.            return mapping.findForward("success");    
  117.        }    
  118.        return mapping.findForward("error");    
  119.     }    
  120.   
  121.     public Userinfo getUser() {    
  122.        return user;    
  123.     }    
  124.     public void setUser(Userinfo user) {    
  125.        this.user = user;    
  126.     }    
  127.     public UserDAO getUserDao() {    
  128.        return userDao;    
  129.     }    
  130.     public void setUserDao(UserDAO userDao) {    
  131.        this.userDao = userDao;    
  132.     }}    
  133.     這里使用setter實(shí)現(xiàn)依賴注入了兩個(gè)bean,接下來配置applicationContext.xml    
  134.     <beans xmlns="略……">    
  135.     <!—- 數(shù)據(jù)源 -->    
  136.     <bean id="dataSource"    
  137.        class="org.apache.commons.dbcp.BasicDataSource">    
  138.        <property name="driverClassName"    
  139.            value="com.mysql.jdbc.Driver">    
  140.        </property>    
  141.         <property name="url"    
  142. value="jdbc:mysql://localhost:3306/demo"></property>    
  143.        <property name="username" value="root"></property>    
  144.        <property name="password" value="root"></property>    
  145.     </bean>    
  146.     <!--  sessionFactory -->    
  147.     <bean id="sessionFactory" class=    
  148. "org.springframework.orm.hibernate3.LocalSessionFactoryBean">    
  149. <property name="dataSource">    
  150.            <ref bean="dataSource" />    
  151.        </property>    
  152.        <property name="hibernateProperties">    
  153.            <props>    
  154.               <prop key="hibernate.dialect">    
  155.                   org.hibernate.dialect.MySQLDialect    
  156.               </prop>    
  157.            </props>    
  158.        </property>    
  159.        <property name="mappingResources">    
  160.            <list>    
  161.               <value>org/chenwj/vo/Userinfo.hbm.xml</value>    
  162.            </list>    
  163.        </property>    
  164.     </bean>    
  165.     <!--  數(shù)據(jù)庫操作類  -->    
  166.     <bean id="userDao" class="org.chenwj.dao.UserDAO">    
  167.        <property name="sessionFactory">    
  168.            <ref local="sessionFactory" />    
  169.        </property>    
  170.     </bean>    
  171.     <!--  action需要注意:這里是name屬性不是ID,同時(shí)要和struts-config.xml    
  172.       對(duì)應(yīng)的 action path屬性值相同,斜線也是必需的,通過這個(gè)屬性scope=    
  173.       "prototype" 每次獲取bean實(shí)例時(shí)都會(huì)產(chǎn)生新的實(shí)例,默認(rèn)是單例-->    
  174.     <bean name="/user" class="org.chenwj.struts.action.UserAction"    
  175.        abstract="false" lazy-init="default" autowire="default"    
  176.        scope="prototype" dependency-check="default">    
  177.        <property name="userDao" ref="userDao" />    
  178.        <property name="user" ref="user" />    
  179.     </bean>    
  180.     <bean id="user" class="org.chenwj.vo.Userinfo" abstract="false"    
  181.        lazy-init="default" autowire="default"    
  182.          dependency-check="default">    
  183.     </bean>    
  184. </beans>    
  185.     到此所有的配置已經(jīng)完成,測(cè)試:    
  186.     HTTP Status 404 - Servlet action is not available    
  187. The requested resource (Servlet action is not available) is not available    
  188. 這個(gè)錯(cuò)誤是大部初學(xué)者整合 SSH 時(shí)都會(huì)遇到的問題    
  189.   
  190.     首先建議你使用測(cè)試類進(jìn)行測(cè)試,這樣我們可以很快找到錯(cuò)誤所在的地方    
  191. public static void main(String[] args) {    
  192.     ApplicationContext context = new FileSystemXmlApplicationContext(    
  193.               "/WebRoot/WEB-INF/applicationContext.xml");    
  194.         UserDAO dao = (UserDAO)context.getBean("userDao");    
  195.        Userinfo user = new Userinfo();    
  196.        user.setName("aaa");    
  197.        user.setPassword("bbb");    
  198.        boolean a = dao.regist(user);    
  199.        if(a){    
  200.            System.out.println("OK");    
  201.        }    
  202.    }    
  203. 如果這里沒出錯(cuò),那么請(qǐng)你好好檢查你的配置文件,是否寫錯(cuò)或少了些什么東東了    
  204.     這里出的錯(cuò)誤也跟使用的版本有關(guān)系,這里報(bào)的錯(cuò)一般都是說找不到XX類所報(bào)的異常    
  205. 那么請(qǐng)檢查lib下有沒commons-pool-1.2.jar包,如沒請(qǐng)導(dǎo)入,這個(gè)問題也有可能是包    
  206. 之間的****,刪除這個(gè)包hibernate-annotations.jar    
  207.   
  208. 六、.sql文件、.jsp文件    
  209. create table userinfo(    
  210.        id int(10) not null auto_increment,    
  211. name varchar(20),    
  212. password varchar(20),    
  213. PRIMARY KEY  (id))    
  214.     <body>    
  215.        <html:form action="/user">    
  216.            name : <html:text property="name"/><br/>    
  217.            password : <html:password property="password"/><br/>    
  218.            <html:submit/><html:cancel/>    
  219.        </html:form>    
  220.     </body>    
  221. 七、作者心聲    
  222.     上面省略了一些類的代碼,當(dāng)然也是不緊要的,請(qǐng)慢看、細(xì)看、多做,相信很容易就可以配置成功。如有必要也可以聯(lián)系我,我這有Demo和視頻教程。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
MyEclipse Spring Hibernate整合開發(fā) - liuxinglanyue - JavaEye技術(shù)網(wǎng)站
struts+spring +ibatis
yanghuw的專欄,第一個(gè)Spring程序
Struts Spring Hibernate整合筆記_TerrySpace
使用struts+spring+hibernate 組裝web應(yīng)用
圖解SSH框架配置步驟
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服