Struts中的controller使用

来源:互联网 发布:软件开发工作思路 编辑:程序博客网 时间:2024/06/07 21:50

在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>

快去试试吧。。

原创粉丝点击