---
title: "6、S2SH及其配置文件详解"
author: "L.G.Alexander"
date: "2009-03-24T13:33:59Z"
tags: []
slug: "6-s2sh"
draft: false
lastmod: "2009-03-24T22:19:31Z"
id: 354167
url: "https://lukuijun.iteye.com/blog/354167"
---

S2SH及其配置文件详解
Strut2:处理页面表单提交过来的信息，处理完之后将结果返回给浏览器显示。
怎么处理？举例:输入校验、国际化等。
Spring:核心就DI和AOP，DI注入对象实例，AOP说白了就是在方法执行之前或者执行之后执行一些动作。
Hibernate:与数据库打交到，把对数据库的操作变成对对象的操作，就是ORM映射工具。
web.xml里面：
       
```xml
 <listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
```
监听器采用观察者模式，Tomcat在启动后，根据我们的配置就会读取一些信息，ContextLoaderListener在容器里面的

一个监听器。
在应用服务器Tomcat启动之后,根据
	
```xml
<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:applicationContext-*.xml</param-value>
	</context-param>
```
加载配置文件后，同时产生BeanFactory,BeanFactory放在ServletContext里面。

```xml
       <filter>
		<filter-name>hibernateFilter</filter-name>
		<filter-class>
			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
		</filter-class>
	</filter>
```

OpenSessionInViewFilter实现了容器里面的Filter接口，OpenSessionInViewFilter复杂打开session或者关闭

session.不用我们去打开或者关闭session,由OpenSessionInViewFilter来给我们做。举例：对于一个web，可能很多

人打开，让我自己去关闭可能会关错。
applicationContext-common.xml中
事物管理器:
   
```xml
 <!-- configure transaction manager-->
    <bean id="transactionManager" 

class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>
    <!-- configure transaction's propagational feature -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes >
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="modify*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="*"  read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <!-- configure which class's which method take part in transaction -->
    <aop:config>
        <aop:pointcut id="allManagerMethod" expression="execution(* com.oa.manager.*.*(..))" />
        <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
    </aop:config>
```
这个事物让spring来给我做，避免了我们手动开启或者关闭事物造成的错误。