gcw633

          s2sh登錄整合(一)配置文件

          配置文件:
          1.web.xml

           1<?xml version="1.0" encoding="UTF-8"?>
           2<web-app version="2.5" 
           3    xmlns="http://java.sun.com/xml/ns/javaee" 
           4    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           5    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
           6    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
           7        <!-- 配置spring的監(jiān)聽器 -->
           8    <listener>
           9        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          10    </listener>
          11    <context-param>
          12        <param-name>contextConfigLocation</param-name>
          13        <param-value>classpath*:applicationContext-*.xml</param-value>
          14    </context-param>
          15    
          16    <!-- hibernate過濾器 -->
          17    <filter>
          18        <filter-name>hibernateFilter</filter-name>
          19        <filter-class>
          20            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
          21    </filter>
          22
          23    <filter-mapping>
          24        <filter-name>hibernateFilter</filter-name>
          25        <url-pattern>*.action</url-pattern>
          26    </filter-mapping>
          27    
          28    <!-- struts2過濾器 -->
          29    <filter>
          30        <filter-name>struts2</filter-name>
          31        <filter-class>
          32    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
          33        </filter-class>
          34    </filter>
          35    <filter-mapping>
          36        <filter-name>struts2</filter-name>
          37        <url-pattern>/*</url-pattern>
          38    </filter-mapping>
          39    
          40    <!-- 編碼過濾器 -->
          41    <filter>
          42        <filter-name>encodingFilter</filter-name>
          43        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
          44        <init-param>
          45            <param-name>encoding</param-name>
          46            <param-value>utf-8</param-value>
          47        </init-param>
          48    </filter>
          49    <filter-mapping>
          50        <filter-name>encodingFilter</filter-name>
          51        <url-pattern>/*</url-pattern>
          52    </filter-mapping>
          53    
          54  <welcome-file-list>
          55    <welcome-file>index.jsp</welcome-file>
          56  </welcome-file-list>
          57</web-app>
          58

          2.hibernate.cfg.xml
           1<?xml version='1.0' encoding='UTF-8'?>
           2<!DOCTYPE hibernate-configuration PUBLIC
           3          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
           4          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
           5<!-- Generated by MyEclipse Hibernate Tools.                   -->
           6<hibernate-configuration>
           7    <session-factory>
           8        <property name="connection.username">sa</property>
           9        <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=demo</property>
          10        <property name="dialect">
          11            org.hibernate.dialect.SQLServerDialect
          12        </property>
          13        <property name="myeclipse.connection.profile">s2shcon2</property>
          14        <property name="connection.password">sa</property>
          15        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
          16        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
          17        <property name="show_sql">true</property>
          18        <mapping resource="com/test/entity/Users.hbm.xml" />
          19    </session-factory>
          20</hibernate-configuration>


          3.applicationContext-*.xml

              (1)applicationContext-common.xml

           1<?xml version="1.0" encoding="UTF-8"?>
           2<beans xmlns="http://www.springframework.org/schema/beans"
           3    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           4    xmlns:p="http://www.springframework.org/schema/p"
           5    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
           6    <!-- 配置SessionFactory -->
           7    <bean id="sessionFactory"
           8        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
           9        <property name="configLocation"
          10            value="classpath:hibernate.cfg.xml">
          11        </property>
          12    </bean>
          13    <!-- 配置事務(wù)管理器 -->
          14
          15    <bean id="transactionManager"
          16        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          17        <property name="sessionFactory" ref="sessionFactory" />
          18    </bean>
          19
          20    <!-- 配置事務(wù)管理 -->
          21    <bean id="transactionBase"
          22        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
          23        lazy-init="true" abstract="true">
          24        <!-- 配置事務(wù)管理器 -->
          25        <property name="transactionManager" ref="transactionManager" />
          26        <!-- 配置事務(wù)屬性 -->
          27        <property name="transactionAttributes">
          28            <props>
          29                <prop key="*">PROPAGATION_REQUIRED</prop>
          30            </props>
          31        </property>
          32    </bean>
          33</beans>

          (2)applicationContext-bean.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

              
          <!-- 將sessionFactory注入到數(shù)據(jù)訪問層dao中 -->
              
          <!-- 用戶管理 -->
              
          <bean id="userDao" parent="transactionBase" >  
                  
          <property name="target">
                      
          <bean class="com.test.dao.impl.UserDaoImpl">
                          
          <property name="sessionFactory">
                              
          <ref bean="sessionFactory"/>
                          
          </property>
                      
          </bean>
                  
          </property>
              
          </bean> 
          </beans>

          (3)applicationContext-service.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

              
          <!-- 將數(shù)據(jù)訪問層中的dao注入到邏輯層中的service中 -->
              
          <bean id="userBiz" class="com.test.biz.impl.UserBizImpl">
                  
          <property name="userDao" ref="userDao"></property>
              
          </bean>
          </beans>

          (4)applicationContext-actions.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
              
              
          <!-- 將邏輯層中的service注入到action中 -->
              
          <bean id="loginAction" class="com.test.actions.LoginAction" scope="prototype">
                  
          <property name="userBiz" ref="userBiz"></property>
              
          </bean>
          </beans>

          (5)struts.xml
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
          <struts>
              
          <package name="struts2" extends="struts-default" namespace="/">
                  
          <action name="login" class="loginAction">
                      
          <result name="success">/index.jsp</result>
                      
          <result name="input">/login.jsp</result>
                      
          <result name="error">/login.jsp</result>
                  
          </action>
              
          </package>
          </struts>

          posted on 2010-04-19 14:26 淡淡的回憶 閱讀(520) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 兖州市| 于田县| 衢州市| 佛教| 镇远县| 闽侯县| 长沙市| 辛集市| 隆回县| 信宜市| 来宾市| 姚安县| 云安县| 白水县| 盐源县| 普安县| 浮梁县| 高淳县| 新乐市| 巫溪县| 边坝县| 河源市| 湖北省| 新巴尔虎右旗| 雷波县| 东至县| 宾阳县| 九台市| 博罗县| 万载县| 成都市| 科技| 彩票| 长宁区| 通许县| 宁乡县| 盐边县| 麻城市| 孝昌县| 信阳市| 宁都县|