Spring 整合Struts的三个小窍门(三)

来源:互联网 发布:浙工大网络教学平台 编辑:程序博客网 时间:2024/05/02 17:16
 窍门 3. 将动作管理委托给 Spring
 步骤:
1. Action 中,使用IOC 获得服务,配置struts-config.xml:
<!-- 一个Action 注意其type Spring 代理类 -->
<action path="/searchSubmit"
type="org.springframework.web.struts.DelegatingActionProxy"
input="/searchEntry.do" validate="true" name="searchForm">
<forward name="success" path="/WEB-INF/pages/detail.jsp" />
<forward name="failure" path="/WEB-INF/pages/search.jsp" />
</action>
2. Spring 配置文件中注册该动作:
<bean id="bookService"
class="ca.nexcel.books.business.BookServiceImpl" />
<bean name="/searchSubmit"
class="ca.nexcel.books.actions.SearchSubmit">
<property name="bookService">
<ref bean="bookService" />
</property>
</bean>

 优点
1. 动作委托解决方法是这三种方法中最好的。
2. 不使用Spring api 编写 Action
3. 利用了IOC 装配
原创粉丝点击