本文主要是介绍用spring容器来接管struts中的action,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在Struts中加入Spring框架的时候,相信大家对
<action-mapping>
<action input="/login.jsp"
name="loginActionForm"
path="/loginAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
</action-mapping>
这段代码 是再熟悉不过吧。不过每个Action都加这个东西。会不会觉得很累呢。有点。。现在好了。。有这个办法可以解决这个问题。
就是在struts-config.xml中的使用<contrlller>
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegationRequestProcessor"/>
</controller>
这样就可以把Struts的Action 交给Spring控制了。。
也不用在Action中写上type="org.springframework.web.struts.DelegatingActionProxy"
最后的代码样式为:
<action-mapping>
<action input="/login.jsp"
name="loginActionForm"
path="/loginAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
</action-mapping>
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegationRequestProcessor"/>
</controller>
快去试试吧。。另外,要注意的在整合三大框架的时候,可能会出现因为三大框架中的某些个.jar包出现冲突,而引发一些问题,不过这些问题都可以通过相应的.jar包之间进行调整。
这篇关于用spring容器来接管struts中的action的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!