在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>
快去試試吧。。