Spring 整合Struts的三个小窍门(二)
2008-11-06 13:28
399 查看
窍门 2. 覆盖 RequestProcessor
1. Action 中,使用IOC 获得服务,配置struts-config.xml:
<!-- 一个普通的Action-->
<action path="/searchSubmit"
type="ca.nexcel.books.actions.SearchSubmit"
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>
<!-- 利用了 <controller> 标记来用 DelegatingRequestProcessor覆盖默认的
Struts RequestProcessor -->
<controller
processorClass="org.springframework.web.struts.
DelegatingRequestProcessor" />
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>
3. 写具有 JavaBean 属性的 Struts 动作:
public class SearchSubmit extends Action {
// 一个Service属性
private BookService bookService;
// getter...
public BookService getBookService() {
return bookService;
}
// setter...
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// 调用bookService,不需要new
Book book = getBookService().read(isbn.trim());
}
}
1. Action 中,使用IOC 获得服务,配置struts-config.xml:
<!-- 一个普通的Action-->
<action path="/searchSubmit"
type="ca.nexcel.books.actions.SearchSubmit"
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>
<!-- 利用了 <controller> 标记来用 DelegatingRequestProcessor覆盖默认的
Struts RequestProcessor -->
<controller
processorClass="org.springframework.web.struts.
DelegatingRequestProcessor" />
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>
3. 写具有 JavaBean 属性的 Struts 动作:
public class SearchSubmit extends Action {
// 一个Service属性
private BookService bookService;
// getter...
public BookService getBookService() {
return bookService;
}
// setter...
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// 调用bookService,不需要new
Book book = getBookService().read(isbn.trim());
}
}
相关文章推荐
- Spring 整合Struts的三个小窍门(一)
- Spring 整合Struts的三个小窍门(三)
- struts+spring+hibernate三个框架的整合
- 整合Struts,Spring,mybatis三个框架的helloworld
- Struts,Hibernate,Spring整合开发中 DATE类型存入和显示问题
- ibatis+spring+struts整合应用实例
- Spring 和struts 整合的三种方式
- Struts 2.0 + Spring 2 + Hibernate 3 整合(含源代码下载)
- Spring 和 struts1.2 整合的三种方式
- jbpm4整合struts2+spring2.5+hibernate3.3
- Spring和Struts整合
- struts,spring和mybatis框架整合
- Struts+mybatis+spring整合tomcat启动报错
- Spring 整合 Struts 的两种方式
- Spring 和 struts1.2 整合的三种方式
- struts2.1+spring2.5+hibernate3.3整合之第一步(spring2.5+hibernate3.3)
- struts2.0与spring2.0的整合 spring和hibernate的整合
- struts整合spring
- 12月1日struts、spring、hibernate等框架的整合培训日记
- Spring2.5.3+Hibernate3.2+Struts2.0.11整合