<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 31  文章 - 2  trackbacks - 0

    雖然是簡單的用戶登錄,但東西一點不少,基于MVC原理實現,共分DAO層,SERVICE層,ACTION層和WEB層,其中DAO和SERVICE層都有各自的接口。

    今天主要講解配置文件的代碼,我學習實例,喜歡從控制層出發,然后用到了哪些類或者JSP,再一一扯“蛋”扯出來。

    當然,還是先看web.xml

    1. <?xml?version="1.0"?encoding="UTF-8"?>??
    2. <web-app?xmlns="http://java.sun.com/xml/ns/j2ee"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?version="2.4"??
    3. ?????????xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee?http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">??
    4. ????<!--?Spring?ApplicationContext配置文件的路徑?,可使用通配符,多個路徑用?1,號分隔,此參數用于后面的Spring-Context?loader?-->??
    5. ????<context-param>??
    6. ????????<param-name>contextConfigLocation</param-name>??
    7. ????????<param-value>classpath*:spring/*.xml</param-value>??
    8. ????</context-param>??
    9. ??
    10. ???? ??
    11. ????<!--?著名?Character?Encoding?filter?-->??
    12. ????<filter>??
    13. ????????<filter-name>encodingFilter</filter-name>??
    14. ????????<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>??
    15. ????????<init-param>??
    16. ????????????<param-name>encoding</param-name>??
    17. ????????????<param-value>UTF-8</param-value>??
    18. ????????</init-param>??
    19. ????</filter>??
    20. ????<!--Hibernate?Open?Session?in?View?Filter-->??
    21. ????<filter>??
    22. ????????<filter-name>hibernateFilter</filter-name>??
    23. ????????<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>??
    24. ????</filter>??
    25. ????<!--?ExtremeTable?導出Excel和Pdf的Filter?-->??
    26. ????<filter>??
    27. ????????<filter-name>eXtremeExport</filter-name>??
    28. ????????<filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>??
    29. ????</filter>??
    30. ????<filter-mapping>??
    31. ????????<filter-name>encodingFilter</filter-name>??
    32. ????????<url-pattern>*.do</url-pattern>??
    33. ????</filter-mapping>??
    34. ????<filter-mapping>??
    35. ????????<filter-name>encodingFilter</filter-name>??
    36. ????????<url-pattern>*.jsp</url-pattern>??
    37. ????</filter-mapping>??
    38. ????<filter-mapping>??
    39. ????????<filter-name>hibernateFilter</filter-name>??
    40. ????????<url-pattern>*.do</url-pattern>??
    41. ????</filter-mapping>??
    42. ??
    43. ??
    44. ????<!--Spring?ApplicationContext?載入?-->??
    45. ????<listener>??
    46. ????????<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>??
    47. ????</listener>??
    48. ??
    49. ????<!--?Spring?刷新Introspector防止內存泄露?-->??
    50. ????<listener>??
    51. ????????<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>??
    52. ????</listener>??
    53. ??
    54. ???? ??
    55. ????<!--?session超時定義,單位為分鐘?-->??
    56. ????<session-config>??
    57. ????????<session-timeout>10</session-timeout>??
    58. ????</session-config>??
    59. ??
    60. </web-app>
    東西很簡單,無非是配置一些過濾器呀,監聽器的。主要講一下openSessionInViewFilter吧,假設在你的應用中 Hibernate是通過spring 來管理它的session.如果在你的應用中沒有使用OpenSessionInViewFilter或者 OpenSessionInViewInterceptor。session會在transaction結束后關閉,此時會拋出session is close 的異常。關于這方面的知識,值得大家去找一下相關資料仔細閱讀。 strut2.xm
    ?
    1. "-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN" ??
    2. ????????"http://struts.apache.org/dtds/struts-2.0.dtd">? ??
    3. <struts?>? ??
    4. ????<include?file?="struts-default.xml"/>???? ??
    5. ???? ??
    6. ????<package?name?="default"?extends?="struts-default">? ??
    7. ????????<action?name="login"?method="login"?class="userAction">??
    8. ????????????<result>/login_success.jspresult>??
    9. ????????????<result?name="input">/login.jspresult>??
    10. ????????action>??
    11. package>??
    12. ???? ??
    13. struts>??
    可能注意到了,這里的Action交給SPRING來管理了。所以我們看一下application.xml的代碼吧
  • <xml?version="1.0"?encoding="UTF-8"?>? ??
  • <beans>??? ??
  • ????<bean?id="dataSource"?class="com.mchange.v2.c3p0.ComboPooledDataSource"?destroy-method="close">?????? ??
  • ????????<property?name="driverClass"?value="oracle.jdbc.driver.OracleDriver"?/>?????? ??
  • ????????<property?name="jdbcUrl"?value="jdbc:oracle:thin:@localhost:1521:oracleDB"?/>?????? ??
  • ????????<property?name="user"?value="xxx"?/>?????? ??
  • ????????<property?name="password"?value="xxx"?/>??????????? ??
  • ???????????????? ??
  • ????????<property?name="minPoolSize"?value="3"?/>???? ??
  • ????????????? ??
  • ????????<property?name="maxPoolSize"?value="30"?/>???? ??
  • ??????????????????? ??
  • ????????<property?name="maxIdleTime"?value="1800"?/>???? ??
  • ??????????????????? ??
  • ????????<property?name="acquireIncrement"?value="3"?/>????? ??
  • ????????<property?name="maxStatements"?value="0"?/>?????? ??
  • ????????<property?name="initialPoolSize"?value="3"?/>?????? ??
  • ??????????? ??
  • ????????<property?name="idleConnectionTestPeriod"?value="60"?/>?????? ??
  • ??????????? ??
  • ????????<property?name="acquireRetryAttempts"?value="30"?/>?????? ??
  • ????????<property?name="breakAfterAcquireFailure"?value="true"?/>?????????? ??
  • ????????<property?name="testConnectionOnCheckout"?value="false"?/>?????? ??
  • ????bean>??? ??
  • ??????? ??
  • ????<bean?id="sessionFactory"?? ??
  • ????????class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">??? ??
  • ????????<property?name="dataSource">??? ??
  • ????????????<ref?bean="dataSource"?/>??? ??
  • ????????property>??? ??
  • ????????<property?name="hibernateProperties">??? ??
  • ????????????<props>??? ??
  • ????????????????<prop?key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialectprop>??? ??
  • ????????????????<prop?key="hibernate.show_sql">trueprop>??? ??
  • ????????????????<prop?key="hibernate.generate_statistics">trueprop>??? ??
  • ????????????????<prop?key="hibernate.connection.release_mode">autoprop>??? ??
  • ????????????????<prop?key="hibernate.autoReconnect">trueprop>???????????????? ??
  • ????????????props>??? ??
  • ????????property>??? ??
  • ????????<property?name="mappingDirectoryLocations">???? ??
  • ????????<list>??? ??
  • ????????????<value>??? ??
  • ????????????????classpath:com/caitong/pingou/bean??? ??
  • ????????????value>??? ??
  • ????????list>???????????????????????????? ??
  • ????????property>??? ??
  • ????bean>???? ??
  • ??????? ??
  • ????<bean?id="transactionManager"?class="org.springframework.orm.hibernate3.HibernateTransactionManager">??????? ??
  • ??????????<property?name="sessionFactory">??????? ??
  • ??????????????<ref?bean="sessionFactory"/>??????? ??
  • ??????????property>??????? ??
  • ????bean>????? ??
  • ??????????? ??
  • ????<bean?id="transactionInterceptor"?class="org.springframework.transaction.interceptor.TransactionInterceptor">??????? ??
  • ????????<property?name="transactionManager"?ref="transactionManager"/>??????? ??
  • ????????<property?name="transactionAttributes">????? ??
  • ????????????<props>????? ??
  • ??????????????????? ??
  • ????????????????<prop?key="add*">PROPAGATION_REQUIREDprop>????? ??
  • ????????????????<prop?key="find*">PROPAGATION_REQUIRED,readOnlyprop>????? ??
  • ????????????props>????? ??
  • ????????property>????? ??
  • ????bean>??????? ??
  • ?????????????? ??
  • ???<bean?class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">??????? ??
  • ????????<property?name="beanNames">????? ??
  • ????????????<value>*Servicevalue>????? ??
  • ????????property>????? ??
  • ????????<property?name="interceptorNames">??????? ??
  • ????????????<list>??????? ??
  • ????????????????<value>transactionInterceptorvalue>??????? ??
  • ??????????????????????? ??
  • ????????????list>??????? ??
  • ????????property>??????? ??
  • ????bean>??????? ??
  • ??????? ??
  • ????<bean?class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">??????? ??
  • ??????????<property?name="transactionInterceptor"?ref="transactionInterceptor"/>??????? ??
  • ????bean>????? ??
  • ??????? ??
  • ????<bean?id="baseDAO"?class="com.caitong.pingou.dao.impl.BaseDAO"?abstract="true">??? ??
  • ????????<property?name="sessionFactory">??? ??
  • ????????????<ref?bean="sessionFactory"/>??? ??
  • ????????property>??? ??
  • ????bean>??? ??
  • ????<bean?id="userDAO"???? ??
  • ????????class="com.caitong.pingou.dao.impl.UserDAO"?parent="baseDAO">??? ??
  • ????bean>??? ??
  • ??????? ??
  • ????<bean?id="userService"?class="com.caitong.pingou.service.impl.UserService"???? ??
  • ????????autowire="byName">??? ??
  • ????bean>??? ??
  • ??????? ??
  • ????<bean?id="userAction"?class="com.caitong.pingou.action.UserAction"????????? ??
  • ????????autowire="byName">??? ??
  • ????bean>??? ??
  • beans>????
  • 應 該說SPRING太強大了,以至于一個配置文件可以解決任何一件事情。簡單介紹一下這個配置文件吧,例子用的是c3p0的數據庫鏈接池, hibernate的配置文件也都集成在這里了,如果細心的讀者,可能注意到了事務管理模塊。是的,本例的事務管理是由spring來管理,而且集中在 service層
    <property?name="beanNames">?? ??
  • ????????????<value>*Servicevalue>?? ??
  • ????????property>?
  • 有人可能提出問題,為什么非得要放在service層,而不是dao層,應該說,事務管理有一個不成文的規定,盡量將問題放在上層處理。
    然后每個類由SPRING來管理,并且autowire="byName"來尋找依賴注入的bean。

    所有的xml文件都已經配置完了,其實最重要也是這個,XML文件將是框架的一個趨勢,掌握了它,其實你已經打開了這個框架的門。



    posted on 2008-03-02 21:12 緣來如此 閱讀(3742) 評論(0)  編輯  收藏 所屬分類: AJAX
    主站蜘蛛池模板: 免费观看日本污污ww网站一区| 亚洲熟女少妇一区二区| 一级中文字幕免费乱码专区 | 亚洲AV成人精品日韩一区18p| 日韩精品免费电影| 亚洲日韩在线观看免费视频| 四虎1515hm免费国产| 久久久久国产精品免费看| 亚洲日韩精品无码AV海量| 亚洲欧洲成人精品香蕉网| 永久免费AV无码国产网站| 亚洲最大在线视频| 亚洲 自拍 另类小说综合图区| 亚洲一区二区在线免费观看| 亚洲日韩中文字幕一区| 亚洲av永久无码精品秋霞电影影院| 美女内射毛片在线看免费人动物| 黄页网址在线免费观看| 亚洲性69影院在线观看| 在线观看国产区亚洲一区成人 | 亚洲欧洲日产国码无码久久99| 美女视频黄a视频全免费| 中文在线观看免费网站| 亚洲日韩一区精品射精| 亚洲免费视频在线观看| 亚洲а∨天堂久久精品| 毛片A级毛片免费播放| 99在线免费观看视频| igao激情在线视频免费| 亚洲人片在线观看天堂无码| 91嫩草私人成人亚洲影院| 久久亚洲国产成人精品无码区| 毛片大全免费观看| 久久国产高潮流白浆免费观看| 国产97视频人人做人人爱免费| jiz zz在亚洲| 亚洲人成网站色在线观看| 97亚洲熟妇自偷自拍另类图片 | 国产一级大片免费看| 114一级毛片免费| 91久久青青草原线免费|