Spring管理Struts Action

可以通过三种方式实现Spring管理Struts Action:

  • 使用 Spring 的 ActionSupport 类整合 Structs
  • 使用 Spring 的 DelegatingRequestProcessor 覆盖 Struts 的 RequestProcessor
  • 将 Struts Action 管理委托给 Spring 框架

本文将讨论第三种方式:

步骤一:在Struts-config.xml中加入Spring插件ContextLoaderPlugin,为 Struts 的 ActionServlet 装载 Spring 应用程序环境。

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 < plug-in  className =

spring来管理action的3种方法 - longterm@yeah - 江洋大盗  "org.springframework.web.struts.ContextLoaderPlugIn" >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗     < set-property  property =

spring来管理action的3种方法 - longterm@yeah - 江洋大盗      "contextConfigLocation"  value ="/WEB-INF/strutsbean.xml" />

spring来管理action的3种方法 - longterm@yeah - 江洋大盗  </ plug-in >

其中strutsbean.xml为定义Struts Action的配置文档。

步骤二:在Struts-config.xml中将Action替换为代理类DelegatingActionProxy,负责在 Spring 环境中查找 Struts 动作。

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 < action     path ="/searchSubmit"  

spring来管理action的3种方法 - longterm@yeah - 江洋大盗     type ="org.springframework.web.struts.DelegatingActionProxy"  

spring来管理action的3种方法 - longterm@yeah - 江洋大盗     name ="searchForm" >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗      < forward  name ="success"  path ="/WEB-INF/pages/detail.jsp" />

spring来管理action的3种方法 - longterm@yeah - 江洋大盗      < forward  name ="failure"  path ="/WEB-INF/pages/search.jsp" />

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 </ action >

其中DelegatingActionProxy会根据path="/searchSubmit",到前面定义的strutsbean.xml文件中找寻相应的Action.

步骤三:定义Struts Action映射文件strutsbean.xml。

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 <? xml version="1.0" encoding="UTF-8" ?>

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 <! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 "http://www.springframework.org/dtd/spring-beans.dtd" >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 < beans >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗   < bean  id ="bookService"  class ="ca.nexcel.books.business.BookServiceImpl" />

spring来管理action的3种方法 - longterm@yeah - 江洋大盗   < bean  name ="/searchSubmit"    

spring来管理action的3种方法 - longterm@yeah - 江洋大盗        class ="ca.nexcel.books.actions.SearchSubmit" >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗      < property  name ="bookService" >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗         < ref  bean ="bookService" />

spring来管理action的3种方法 - longterm@yeah - 江洋大盗      </ property >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗   </ bean >

spring来管理action的3种方法 - longterm@yeah - 江洋大盗 </ beans >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值