strut2和spring框架都是比较优秀的开源框架,各有优缺点。这两个框架的整合使用将使得业务逻辑和层次更加清晰明了。在大部分struts,spring框架运用中,一般的角色分配是这样的:Struts2框架负责流程和前端视图的解析,而Spring框架通过反转控制(IOC)的机制负责对象的实例创建,不仅如此,spring框架还可以用AOP面向切面编程的形式,拓展整个web应用的功能,使得各个组件之间的耦合性降低。。。。。。。
struts2和spring框架的整合分以下几步:
一:加入spring和struts各自需要的jar包
注意:
其中struts2-spring-pluging-2.3.24.jar包要加上,不要忘加了。
二:在web.xml文件中添加struts2框架的过滤器和spring框架的监听器
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>spring_1</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置struts2的拦截器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter</