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帛罗阁 阅读(1809) 评论(0)  编辑  收藏 所属分类: 开源软件


只有注册用户登录后才能发表评论。


网站导航:
 

导航

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

统计

常用链接

留言簿(15)

随笔分类

随笔档案

相册

收藏夹

博客

文档

站点

论坛

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜