将 Struts Action 管理委托给 Spring 框架
(1):在Struts-config.xml中加入Spring插件ContextLoaderPlugin,为 Struts 的 ActionServlet 装载 Spring 应用程序环境。
-
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> < plug - in className = " org.springframework.web.struts.ContextLoaderPlugIn " > < set - property property = " contextConfigLocation " value = " /WEB-INF/struts.xml " /> </ plug - in >
(2):在Struts-config.xml中将Action替换为代理类DelegatingActionProxy,负责在 Spring 环境中查找 Struts 动作。
-
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> < action path = " /test " type = " org.springframework.web.struts.DelegatingActionProxy " name = " testForm " > // 其中DelegatingActionProxy会根据path="/test",到1步骤的struts.xml文件中找寻相应的Action. < forward name = " success " path = " /WEB-INF/pages/success.jsp " /> < forward name = " failure " path = " /WEB-INF/pages/failure.jsp " /> </ action >
(3):讲struts装载到Spring。
-
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> < beans > < bean id = " testBiz " class = " org.xixi.biz.bizImpl.testImpl " /> < bean name = " /test " // 根据name属性注入2步骤action里的其它子节点特性(在这时spring也同时融入了自己的特性,比如将Biz注入action) class = " org.xixi.web.actions.Test " > < property name = " testBiz " > < ref bean = " testBiz " /> </ property > </ bean > </ beans >
上面的是spring管理struts的最常用的方法.
此外,还可以使用Spring的ActionSupport类或使用Spring的DelegatingRequestProcessor覆盖Struts的RequestProcessor达到整合的目的.