spring 负责对象创建
struts 用Action处理请求
说明:
spring版本:spring-framework-3.2.5.RELEASE
struts版本:struts-2.3.30
- 创建一个JavaWeb的project
- 引入struts2的required的jar包
commons-fileupload-1.3.2.jar
commons-io-2.2.jar
commons-lang3-3.2.jar
freemarker-2.3.22.jar
javassist-3.11.0.GA.jar
ognl-3.0.19.jar
struts2-core-2.3.30.jar
xwork-core-2.3.30.jar
- 引入spring3的required的jar包
commons-logging-1.1.3.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-core-3.2.5.RELEASE.jar
spring-expression-3.2.5.RELEASE.jar
- 引入spring-web支持的jar包
- spring-web-3.2.5.RELEASE.jar [spirng源码包]
- struts2-spring-plugin-2.3.4.1.jar [struts源码包]
- 引入配置文件
- struts.xml [struts路径与action映射配置]
- bean.xml [spring的IOC容器配置]
- web.xml [添加struts2的核心过滤器:StrutsPrepareAndExecuteFilter]
[添加核心监听器,初始化spring的IOC容器:ContextLoaderListener]
<!-- 1.struts2配置 -->
<filter>
<filter-name>struts2</filter-name>
<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配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/bean*.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>