为什么80%的码农都做不了架构师?>>>   

struts与spring整合方法

<!-- 载入applicationContext上下文--> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/*applicationContext*.xml</param-value> 
</context-param>

第一种:使用 Spring 的 ActionSupport 类整合 Structs

继承spring的ActionSupport类

public class ShowDeptListAction extends ActionSupport {

public ActionForward execute(ActionMapping mapping, ActionForm form, 
       HttpServletRequest request, HttpServletResponse response) {

DeptManager deptManager = (DeptManager) getWebApplicationContext() 
        .getBean("deptManager"); 
      List<Dept> list = deptManager.getAllDept(); 
      request.setAttribute("list", list); 
      return mapping.findForward("ok");

}

}

第二种:使用 Spring 的 DelegatingRequestProcessor 覆盖 Struts 的 RequestProcessor

在struts-config.xml 文件加入:

<controller     processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />

在spring上下文配置文件中作为bean注册:

<beans> 
<bean name="/showDeptList" 
     class="cn.com.thinkbank.struts.action.ShowDeptListAction"> 
     <property name="deptManager" ref="deptManager" > 
     </property> 
</bean> 
</beans>

servlet代码类如下:

public class ShowDeptListAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form, 
      HttpServletRequest request, HttpServletResponse response) {

List<Dept> list = deptManager.getAllDept(); 
     request.setAttribute("list", list); 
     return mapping.findForward("ok");

}

private DeptManager deptManager;

public void setDeptManager(DeptManager deptManager) { 
     this.deptManager = deptManager; 
}

}

第三种:将 Struts Action 管理委托给 Spring 框架 
在struts-config.xml 文件加入:

<action-mappings> 
     <action path="/showDeptList" 
   type="org.springframework.web.struts.DelegatingActionProxy"> 
      <forward name="ok" path="/form/showDeptList.jsp"></forward> 
     </action> 
</action-mappings>

在spring上下文配置文件中作为bean注册:

<bean name="/showDeptList" 
     class="cn.com.thinkbank.struts.action.ShowDeptListAction"> 
     <property name="deptManager" ref="deptManager" > 
     </property> 
</bean>

servlet代码类如下:

public class ShowDeptListAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form, 
      HttpServletRequest request, HttpServletResponse response) {

List<Dept> list = deptManager.getAllDept(); 
     request.setAttribute("list", list); 
     return mapping.findForward("ok");

}

private DeptManager deptManager;

public void setDeptManager(DeptManager deptManager) { 
     this.deptManager = deptManager; 
}

}

转载于:https://my.oschina.net/os3/blog/89973

struts与spring整合方法copy相关推荐

  1. Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。...

    1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...

  2. Struts+Spring整合方式

    struts与spring整合方式有三种: 方式一:通过Spring的ActionSupport类实现. 方式二:通过Sping的DelegatingRequestProcessor类覆盖struts ...

  3. spring 整合struts

    1.例子:未被spring整合 struts.xml 的配置文件 <constant name="struts.enable.DynamicMethodInvocation" ...

  4. shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决

    shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决 from :http://blog.csdn.net/babys/article/ ...

  5. Struts 2+Spring 3+Hibernate 3.3 在MyEclipse 10环境下的整合配置

    想动手做一个SSH框架下的登录注册功能,虽然网上类似的教程很多,可是看了一圈,不是版本问题,就是漏掉了许多关键的步骤.经过几个小时的奋战,终于搞定了所谓很简单的SSH整合实现注册功能,下面把所有的步骤 ...

  6. Struts+iBatis+Spring+mysql整合开发

    转载请注明:http://www.cnblogs.com/tiantianbyconan/archive/2013/03/03/2941554.html 本文使用Struts+iBatis+Sprin ...

  7. Spring 整合Mybatis Mapper动态代理方法

    先看项目目录结构 很清爽了 最重要的Spring的核心配置文件,看一下 <?xml version="1.0" encoding="UTF-8"?> ...

  8. Strutsw2与Spring整合流程-简述

    1.      新建WEB工程: 2.      导入struts2开发包,和资源配置文件 ① globalMessages.properties ② struts.properties 3.     ...

  9. Struts2+Hibernate+Spring 整合示例

    转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...

最新文章

  1. 刷新三项世界纪录的跨镜追踪(ReID)技术是怎样实现的?进来了解一下
  2. WinForm下PictureBox和Panel控件的On_Paint事件有何区别
  3. AlertDialog.Builder 显示为白色 蓝色字
  4. 使用Silverlight for Embedded开发绚丽的界面(4)
  5. 清除window 系统中的垃圾文件-转
  6. vue 可视化布局工具_GitDataV一款Github的'大数据可视化平台'
  7. linux 复制包括子目录_【Linux分享】Linux常用命令+教程分享
  8. 【Python】局部变量和全局变量以及组合数据(列表)类型
  9. 【Gym - 101915D】Largest Group(二分图最大团,状压dp)
  10. iMac 是什么?苹果2021新款 iMac 购买建议
  11. 禾匠榜店小程序商城V4独立版V4.0.25 前端+后端
  12. code css怎么拿不到div_哈登和威少再怎么努力,也追不上杜兰特,因为刷子是拿不到冠军的...
  13. 【人民币识别】基于matlab GUI RGB和BP神经网络的人民币识别系统【含Matlab源码 097期】
  14. Struts2 面试题
  15. 计算机网络管理员二级考试题,计算机网络管理员(二级)操作鉴定试题A
  16. 大前研一:聪明人必作的十件事
  17. MYSQL union 联合查询
  18. maya python 游戏与影视编程指南pdf_Maya Python 游戏与影视编程指南
  19. Beautiful Soup 4 的安装与使用
  20. 让味蕾动起来的蛋糕甜点

热门文章

  1. scala(10)-----Scala 闭包
  2. Node.js入门以及第一个helloworld程序.
  3. java中如果需要返回多个值怎么办
  4. 设计模式六大原则——迪米特法则(LoD)
  5. Idea tomcat get 乱码
  6. bzoj4195 noi2015 day1 t1
  7. Mysql group by,order by,dinstict优化
  8. 深入分析FreeDos -- 前言
  9. curl工具使用实例
  10. Django基础-Web框架-URL路由