1 Struts。xml 使用拦截器

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

<struts>
    <include file="struts-user.xml"/>
    <include file="struts-order.xml"/>
    <include file="struts-cart.xml"/>
    <include file="struts-main.xml"/>
    <package name="dang-Default" extends="json-default">
        <!-- <interceptors>
            <interceptor name="transaction"
            class="com.tarena.dang.interceptor.TransactionInterceptor"/>
            <interceptor-stack name="dangStack">
                <interceptor-ref name="transaction"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>
        所有Action请求使用dangStack拦截器
        <default-interceptor-ref name="dangStack"/>
        指定默认响应的Action
        <default-action-ref name="index"/>
        
        定义共通的拦截器,Result和Action组件
        <global-results>
            <result name="error">
                /error.jsp
            </result>
        </global-results>
        
        <global-exception-mappings>
            <exception-mapping
                    exception="java.lang.Exception"
                    result="error"/>
        </global-exception-mappings> -->
    
        <!-- 处理默认响应的Action,
        以redirect方式调用/mian空间下
        的index请求的Action -->
        <action name="index">
            <result type="redirectAction">
                <param name="namespace">/main</param>
                <param name="actionName">index</param>
            </result>
        </action>
    
    </package>
    
</struts>

 2.Spring 的配置文件

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    <!-- 指定properties文件,后面使用${}获取 -->
    <context:property-placeholder location="classpath:db.properties" />

<bean id="dataSource" destroy-method="close"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url" value="${url}">
        </property>
        <property name="driverClassName" value="${driverClassName}">
        </property>
        <property name="username" value="${username}">
        </property>
        <property name="password" value="${password}">
        </property>
        <property name="initialSize" value="${initialSize}">
        </property>
        <property name="maxActive" value="${maxActive}">
        </property>
    </bean>

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">${dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <!-- 如果在Dao中使用private SessionFactory sessionFactory;
                                 private Session getSession(){
                                    return sessionFactory.openSession();
                                 }
                必须加入该语句                  -->
                <prop key="hibernate.current_session_context_class">thread</prop>  
            </props>
        </property>
    <!--     <property name="current_session_context_class">thread</property>  -->
        
<!--    出现问题

   <property name="mappingResources"
            value="classpath:com/tarena/dang/pojo/*.hbm.xml">
        </property>
         -->
         <property name="mappingResources">
            <list>
                <value>com/tarena/dang/pojo/DBook.hbm.xml</value>
                <value>com/tarena/dang/pojo/DCategory.hbm.xml</value>
                <value>com/tarena/dang/pojo/DCategoryProduct.hbm.xml</value>
                <value>com/tarena/dang/pojo/DComment.hbm.xml</value>
                <value>com/tarena/dang/pojo/DCommentReply.hbm.xml</value>
                <value>com/tarena/dang/pojo/DItem.hbm.xml</value>
                <value>com/tarena/dang/pojo/DOrder.hbm.xml</value>
                <value>com/tarena/dang/pojo/DProduct.hbm.xml</value>
                <value>com/tarena/dang/pojo/DSendWay.hbm.xml</value>
                <value>com/tarena/dang/pojo/DUser.hbm.xml</value>
            </list>
        </property>
    </bean>

<context:component-scan base-package="com.tarena.dang"></context:component-scan>
    
    
</beans>

3. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
      <filter>
        <filter-name>struts2filter</filter-name>
        <filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>struts2filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext-*.xml</param-value>
    </context-param>
 
  <listener>
      <listener-class>
org.springframework.web.context.ContextLoaderListener
      </listener-class>
  </listener>
 
  <listener>
      <listener-class>
org.springframework.web.context.request.RequestContextListener
      </listener-class>
  </listener>
 
 
  <welcome-file-list>
    <welcome-file>/user/userForm.jsp</welcome-file>
  </welcome-file-list>
</web-app>

有些问题的解释:http://hengstart.iteye.com/blog/858081

SSH三大框架整合使用的配置文件 注解实现的更多相关文章

  1. Maven SSH三大框架整合的加载流程

    <Maven精品教程视频\day02视频\03ssh配置文件加载过程.avi;> 此课程中讲 SSH三大框架整合的加载流程,还可以,初步接触的朋友可以听一听. < \day02视频\ ...

  2. SSH三大框架整合案例

    SSH三大框架的整合   SSH三个框架的知识点 一.Hibernate框架 1. Hibernate的核心配置文件 1.1 数据库信息.连接池配置 1.2 Hibernate信息 1.3 映射配置 ...

  3. JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo

    三大框架整合 一.SSH导包 二.书写Spring 三.书写Struts 四.整合Spring与Struts 五.书写(与整合)Hibernate.引入c3p0连接池并使用hibernate模板 六. ...

  4. SSH三大框架整合配置详解

    首先,三大框架整合,肯定是要导入相当多的jar包,这是不容置疑的!     这里就不一一列举了,直接截图吧:             (1) 基于配置文件的整合:        第一步:我们需要在we ...

  5. 关于ssh三大框架整合的碎碎念

    三大框架整合,无非就是一个导jar包,修改配置文件的过程.完了就没事了. 还是有很多细节性的问题 比如在spring中写applicationContext.xml文件时不提示: 解决方法如下: 如果 ...

  6. SSH 三大框架整合

    Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 每次请求都会创建一个Spring的工厂,这样浪费服务器资源,应该一个项目只有一个Spring的工厂. 在服务器启动 ...

  7. JAVAEE——SSH三大框架整合(spring+struts2+hibernate)

    一.整合原理 二.导包(41个) 1.hibernate (1)hibernate/lib/required (2)hibernate/lib/jpa | java persist api java的 ...

  8. SSH三大框架整合步骤

    Struts2:需要整合的第一个框架: 1.创建一个动态web项目 2.导入struts2必须的jar 放到 lib目录下 ,再 build path 添加web工程中 3.配置struts2的核心配 ...

  9. SSH三大框架整合配置详细步骤(3)

    5 配置Spring2.5 5.1 基础配置 1)        导入spring包.下载spring-framework-2.5.6并解压后,在spring-framework-2.5.6" ...

随机推荐

  1. objective-c里的方法指针IMP的用法

    SGPopSelectView.h @interface SGPopSelectView : UIView @property (nonatomic, assign) SEL selector; @p ...

  2. acdream 1210 Chinese Girls' Amusement (打表找规律)

    题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次 ...

  3. 【Java学习笔记】数组使用

    package aaa; public class aaa { public static void main(String args[]) { int a[]={1,2,3,4}; for(int ...

  4. web项目Log4j日志输出路径配置问题

    问题描述:一个web项目想在一个tomcat下运行多个实例(通过修改war包名称的实现),然后每个实例都将日志输出到tomcat的logs目录下实例名命名的文件夹下进行区分查看每个实例日志,要求通过尽 ...

  5. 嵌入式 hi3518c平台网卡模式MII与RMII模式在Uboot和kernel中切换小结

    由于公司项目的需要,我们需要在原有的MII的基础上,修改为RMII模式,针对hi3518c平台,我的网卡是LAN8701需要修改的地方有如下几个: 首先我的uboot中env是: bootargs=m ...

  6. MySQL备份与复制

    1.二进制日志 二进制日志记录了数据库的所有改变,使得任何slave都可以执行相同的更新.一般来说,开启二进制日志大概会有1%的性能损耗,它有两个重要的使用场景: (1)备份:在某个时间点t作了一次备 ...

  7. git学习一

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...

  8. SPOJ DISUBSTR Distinct Substrings 后缀数组

    题意:统计母串中包含多少不同的子串 然后这是09年论文<后缀数组——处理字符串的有力工具>中有介绍 公式如下: 原理就是加上新的,减去重的,这题是因为打多校才补的,只能说我是个垃圾 #in ...

  9. <转>Python 多线程的单cpu与cpu上的多线程的区别

    你对Python 多线程有所了解的话.那么你对python 多线程在单cpu意义上的多线程与多cpu上的多线程有着本质的区别,如果你对Python 多线程的相关知识想有更多的了解,你就可以浏览我们的文 ...

  10. Casperjs/PhantomJs 中文网站截图乱码

    使用CasperJs进行自动化测试中文网站的时候发现中文网站截图会出现乱码的现象,中文汉字被一个个小方框代替 查找了一些资料发现是因为Linux服务器上没有安装中文字体导致的,Linux如何安装中文字 ...