spring管理struts

本文介绍了如何将StrutsAction管理委托给Spring框架,通过在Struts-config.xml中加入Spring插件ContextLoaderPlugin,实现Struts与Spring的无缝集成。包括在配置文件中替换Action,将Struts动作装载到Spring环境,以及利用Spring的特性如注入Biz等。


           将 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达到整合的目的.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值