三大框架文件配置

web.xml 文件配置
1.strtus2 配置文件(配置过滤器)

  <filter>
        <!-- 过滤器名字  -->
        <filter-name>struts2</filter-name>
        <!--  过滤器支持的struts2类  -->
        <!-- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> -->
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>

    <filter-mapping>
        <!-- 过滤器拦截名字  -->
        <filter-name>struts2</filter-name>
        <!-- 过滤器拦截文件路径名字  -->
        <url-pattern>/*</url-pattern>
    </filter-mapping>

2.spring 配置文件(配置加载文件及监听)

  <!-- 配置spring的加载文件路径及文件名称 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- 使用spring自带的监听器,其默认加载的是WEB-INF下的applicationContext.xml -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

#3.防止使用get方式提交时乱码的配置

      <filter>
             <filter-name>CharacterEncodingFilter</filter-name>
             <filter-class>
                 org.springframework.web.filter.CharacterEncodingFilter
             </filter-class>
             <init-param>
                 <param-name>encoding</param-name>
                 <param-value>utf-8</param-value>
             </init-param>
             <init-param>
                 <param-name>forceEncoding</param-name>
                 <param-value>true</param-value>
             </init-param>
         </filter>
         <filter-mapping>
             <filter-name>CharacterEncodingFilter</filter-name>
             <url-pattern>*.html</url-pattern>
         </filter-mapping>
         <filter-mapping>
             <filter-name>CharacterEncodingFilter</filter-name>
             <url-pattern>*.jsp</url-pattern>
         </filter-mapping>
         <filter-mapping>
             <filter-name>CharacterEncodingFilter</filter-name>
             <url-pattern>*.action</url-pattern>
         </filter-mapping>


struts2配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
    <constant name="struts.i18n.encoding" value="UTF-8"/>

    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

    <!-- 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts 2处理。    
    如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->
    <constant name="struts.action.extension" value="action"/>
   
    <!-- 开发阶段设置 -->
    <!-- 设置浏览器是否缓存静态内容,默认值为true,开发阶段最好false -->
    <constant name="struts.serve.static.browserCache " value="false"/>

    <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,
    默认值为false,开发阶段最好true -->
    <constant name="struts.configuration.xml.reload" value="true"/>

    <!-- 开发模式下设为true,这样可以打印出更详细的错误信息 -->
    <constant name="struts.devMode" value="true"/>
    <!-- struts2的bean交给spring管理 -->
    <constant name="struts.objectFactory" value="spring" />
    
    <!-- 全局抽象包,定义登录拦截器 -->
    <package name="abstract_struts" abstract="true" extends="struts-default" namespace="/">
      <interceptors>
           <interceptor-stack name="myStack">
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <interceptor-ref name="authority"></interceptor-ref>
           </interceptor-stack>
               <interceptor name="authority" class="com.seecen.exam.intercept.LoginInterceptor"></interceptor>
           </interceptors>
      <default-interceptor-ref name="myStack" />
      <!-- 定义全局Result -->  
      <global-results>  
        <!-- 当返回login视图名时,转入/login.jsp页面 -->  
        <result name="login">/login.jsp</result>  
        <result name="input">/fail.jsp</result>
      </global-results>
    </package>
    <include file="struts-login.xml"></include>
</struts>

 

 

 

spring 配置文件 spring 整合 Hibernate
applicationContext.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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-4.0.xsd
               http://www.springframework.org/schema/tx
               http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
               
    <!-- 引入jdbc配置文件 -->
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath*:jdbc.properties</value>
            </list>
        </property>
    </bean>
    <!-- 配置数据源,使用DBCP数据源 --><!-- c3p0 -->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <!-- Oracle数据库的驱动 -->
        <property name="driverClassName" value="${jdbc.driver}" />
        <!-- 数据库的URL -->
        <property name="url" value="${jdbc.url}" />
        <!-- 指定数据库的用户名 -->
        <property name="username" value="${jdbc.username}" />
        <!-- 指定数据库的密码 -->
        <property name="password" value="${jdbc.pwd}" />
        <!-- 指定数据库的最大连接数100 -->
        <property name="maxActive" value="100" />
        <!-- 指定数据库的最大空闲连接数30 -->
        <property name="maxIdle" value="30" />
        <!-- 指定数据库的最大等待数300 -->
        <property name="maxWait" value="300" />
        <!-- 指定数据库的默认自动提交 -->
        <property name="defaultAutoCommit" value="true" />
        <!-- 指定数据库的连接超时时是否启动自动回收 -->
        <property name="removeAbandoned" value="true" />
        <!-- 指定数据库的删除数据库连接的超时时长 -->
        <property name="removeAbandonedTimeout" value="60" />
        <!-- 记录没有关闭的链接日志 -->
        <property name="logAbandoned" value="true" />
    </bean>

    <!-- 配置Hibernate的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!-- 依赖注入SessionFactory所需的DataSource-->
        <property name="dataSource" ref="dataSource" />
        <!-- 加载所有的映射文件 -->
        <property name="mappingResources">
            <list>
                 <value>com/seecen/config/Dept.hbm.xml</value>
                 <value>com/seecen/config/User.hbm.xml</value>
            </list>
        </property>
        <!-- 下面指定Hibernate的属性 -->
        <property name="hibernateProperties">
            <props>
                <!--下面指定Hibernate使用的数据库方言 -->
                <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
            </props>
        </property>
    </bean>
    
    <!--?声明一个?Hibernate?4?的事务管理器供代理类自动管理事务用?-->
    <bean id="myTxManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    
    <!-- 创建事物切面 -->
    <tx:advice id="txAdvice" transaction-manager="myTxManager">
        <tx:attributes>
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />
            <tx:method name="validate*" propagation="REQUIRED" read-only="true" />
            <tx:method name="is*" propagation="REQUIRED" read-only="true" />
            <tx:method name="log*" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="calculate*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="productServiceMethods" expression="execution(* com.seecen..service.impl.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
    </aop:config>
    
    <import resource="applicationContext-action.xml" />
    <import resource="applicationContext-service.xml" />
    <import resource="applicationContext-dao.xml" />
    
</beans>    

 

posted @ 2015-01-28 11:00  江湖一笑  阅读(203)  评论(0编辑  收藏  举报