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 <!-- 1.struts2配置 --> 2 <filter> 3 <filter-name>struts2</filter-name> 4 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 5 </filter> 6 <filter-mapping> 7 <filter-name>struts2</filter-name> 8 <url-pattern>/*</url-pattern> 9 </filter-mapping> 10 11 <!-- 2.spring配置 --> 12 <context-param> 13 <param-name>contextConfigLocation</param-name> 14 <param-value>/WEB-INF/classes/bean*.xml</param-value> 15 </context-param> 16 17 <listener> 18 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 19 </listener>