spring和struts2

来源:互联网 发布:itools pro mac破解版 编辑:程序博客网 时间:2024/06/10 21:44

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对应的beanid,如果struts2也使用注解的话,struts2.xml中只需要配置这个常量就ok

3.用到的jar最好从网上下载现成的,如果要自己配,那么就先导入平时struts2的包》导入struts2spring的插件导入spring的核心包和aop的包再导入spring操作数据的包如果用到了hibernate再导入hibernate的包,把其中名字相同的低版本的删除,在运行过程中出现少哪个包,再往里加.更高明的是了解包和包之间的依赖关系,以及冲突.不详述。Over