Spring使用 struts2来处理web请求
核心思想:在web启动时加载spring容器,struts中用来处理请求的action从spring容器中获取
1.在web.xml中配置struts2的过滤器,以及加载spring的配置文件,下面是加载配置文件的配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/auscend/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.把所有的action都配置在spring的容器中,在struts.xml中指定action不是自己创建了,而是从spring容器中获得,配置常量struts.objectFactory=spring,Action元素中的class不需要写class了而是写action对应的bean的id,如果struts2也使用注解的话,struts2.xml中只需要配置这个常量就ok
3.用到的jar包最好从网上下载现成的,如果要自己配,那么就先导入平时struts2的包》导入struts2中spring的插件》导入spring的核心包和aop的包》再导入spring操作数据的包》如果用到了hibernate再导入hibernate的包,把其中名字相同的低版本的删除,在运行过程中出现少哪个包,再往里加.更高明的是了解包和包之间的依赖关系,以及冲突.不详述。Over