Dev@Free

          zJun's Tech Weblog

          Spring管理Struts Action

          參考文檔: 使用 Spring 更好地處理 Struts 動作

          可以通過三種方式實現Spring管理Struts Action:

          • 使用 Spring 的 ActionSupport 類整合 Structs
          • 使用 Spring 的 DelegatingRequestProcessor 覆蓋 Struts 的 RequestProcessor
          • 將 Struts Action 管理委托給 Spring 框架

          本文將討論第三種方式:

          步驟一:在Struts-config.xml中加入Spring插件ContextLoaderPlugin,為 Struts 的 ActionServlet 裝載 Spring 應用程序環境。

          < plug-in  className =
            "org.springframework.web.struts.ContextLoaderPlugIn"
          >

              
          < set-property  property =
                "contextConfigLocation"
           value ="/WEB-INF/strutsbean.xml" />

           
          </ plug-in >

          其中strutsbean.xml為定義Struts Action的配置文檔。

          步驟二:在Struts-config.xml中將Action替換為代理類DelegatingActionProxy,負責在 Spring 環境中查找 Struts 動作。

          < action     path ="/searchSubmit"  
               type
          ="org.springframework.web.struts.DelegatingActionProxy"
           
               name
          ="searchForm" >

               
          < forward  name ="success"  path ="/WEB-INF/pages/detail.jsp" />
               
          < forward  name ="failure"  path ="/WEB-INF/pages/search.jsp" />
          </ action >

          其中DelegatingActionProxy會根據path="/searchSubmit",到前面定義的strutsbean.xml文件中找尋相應的Action.

          步驟三:定義Struts Action映射文件strutsbean.xml。

          <? xml version="1.0" encoding="UTF-8" ?>
          <! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
           "http://www.springframework.org/dtd/spring-beans.dtd"
          >

          < beans >
            
          < 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 >
          </ beans >

          posted on 2007-01-08 16:57 zJun's帛羅閣 閱讀(1837) 評論(0)  編輯  收藏 所屬分類: 開源軟件

          導航

          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          統計

          常用鏈接

          留言簿(15)

          隨筆分類

          隨筆檔案

          相冊

          收藏夾

          博客

          文檔

          站點

          論壇

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 霍林郭勒市| 育儿| 昂仁县| 钦州市| 玉树县| 万载县| 凤山县| 三穗县| 汝城县| 南华县| 田东县| 永胜县| 中江县| 营口市| 开江县| 泰顺县| 安塞县| 霞浦县| 嵩明县| 姜堰市| 昭平县| 九台市| 高州市| 定西市| 根河市| 昂仁县| 太保市| 西乌珠穆沁旗| 武清区| 闽侯县| 长乐市| 汝阳县| 莱阳市| 莱西市| 宁化县| 赤峰市| 河间市| 酉阳| 罗甸县| 太仓市| 彩票|