一、单独测试strust

1.action

 package cn.itcast.oa.test;

 import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service; import com.opensymphony.xwork2.ActionSupport; //@Component("testAction")
//@Service
//@Repository
@Controller("testAction")
@Scope("prototype")
public class TestAction extends ActionSupport { @Override
public String execute() throws Exception {
System.out.println("---> TestAction.execute()");
return "success";
}
}

2.struts.xml

    <package name="default" namespace="/" extends="struts-default">

        <!-- 配置测试用的Action,未与Spring整合,class属性写类的全名 -->
<!-- 当Struts2与Spring整合后,class属性可以写bean的名称 -->
<action name="test" class="testAction">
<result name="success">/test.jsp</result>
</action> </package>

3.test.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head> <body>
测试 action. <br>
struts与spring整合成功. <br>
</body>
</html>

4.访问http://localhost:8080/MyOA/test.action

二、单独测试srping

1.java

 public class SpringTest {

     private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

     @Test
public void testBean() throws Exception {
TestAction testAction = (TestAction) ac.getBean("testAction");
System.out.println(testAction);
}

2.applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 自动扫描(包含子包)与装配bean以便可以写注解 -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan>

三、整合

1.添加struts2-spring-plugin-2.1.8.1.jar

2.在web.xml中添加spring监听器

     <!-- 配置Spring的用于初始化容器对象的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>

ps:整合后,struts.xml的action可以写对象名,不用写全路径

    <package name="default" namespace="/" extends="struts-default">

        <!-- 配置测试用的Action,未与Spring整合,class属性写类的全名 -->
<!-- 当Struts2与Spring整合后,class属性可以写bean的名称 -->
<action name="test" class="testAction">
<result name="success">/test.jsp</result>
</action> </package>

OA学习笔记-005-Spring2.5与struts2.1整合的更多相关文章

  1. OA学习笔记-001-项目介绍

    基本知识 框架工具 解决方案(经典应用) 项目 12天 ========================================== OA项目, 12天 BBS 一.什么是OA? 辅助管理.提 ...

  2. [struts2学习笔记] 第五节 编写struts2的action代码

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/40479299 官方文档: http://struts.apache.org/relea ...

  3. 【Struts2学习笔记(12)】Struts2国际化

    (1)准备资源文件,资源文件的命名格式例如以下: baseName_language_country.properties baseName_language.properties baseName. ...

  4. OA学习笔记-010-Struts部分源码分析、Intercepter、ModelDriver、OGNL、EL

    一.分析 二. 1.OGNL 在访问action前,要经过各种intercepter,其中ParameterFilterInterceptor会把各咱参数放到ValueStack里,从而使OGNL可以 ...

  5. OA学习笔记-009-岗位管理的CRUD

    一.分析 Action->Service->Dao CRUD有功能已经抽取到BaseDaoImpl中实现,所以RoleDaoImpl没有CRUD的代码,直接从BaseDaoImpl中继承 ...

  6. OA学习笔记-008-岗位管理Action层实现

    一.分析 1,设计实体/表 设计实体 --> JavaBean --> hbm.xml --> 建表 2,分析有几个功能,对应几个请求. 3,实现功能: 1,写Action类,写Ac ...

  7. OA学习笔记-006-SPRING2.5与hibernate3.5整合

    一.为什么要整合 1,管理SessionFactory实例(只需要一个) 2,声明式事务管理 spirng的作用 IOC 管理对象.. AOP 事务管理.. 二.整合步骤 1.整合sessionFac ...

  8. OA学习笔记-004-Spring2.5配置

    一.jar包 (1)spring.jar (2)Aop包 aspectjrt.jaraspectjweaver.jar (3)动态代理 cglib-nodep-2.1_3.jar (4)日志 comm ...

  9. OA学习笔记-003-Hibernate3.6配置

    一.jar包:核心包, 必须包, jpa, c3p0, jdbc antlr-2.7.6.jarc3p0-0.9.1.jarcommons-collections-3.1.jardom4j-1.6.1 ...

随机推荐

  1. Linux软件安装与卸载

    一. 了解Linux应用软件安装包: 通常Linux应用软件的安装包有三种: 1) tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. 2) rp ...

  2. Jquery Table添加行、删除行

    html页面代码 <table id="tblUserInfo"> </table> Js代码 function DealUserInfo(qty){ ) ...

  3. 20160314 Servlet 入门

    一.Servlet 1.sun提供的一种动态web资源开发技术.本质上就是一段java小程序.可以将Servlet加入到Servlet容器中运行. *Servlet容器 -- 能够运行Servlet的 ...

  4. Gerrit 删除项目

    今天手滑把一个Gerrit上的项目epa写成了epp,想找个重命名的地方也找不到...到网络上搜索了下,发现都是改数据库的,然后就进入的数据库: $ ssh -p 29418 10.27.149.22 ...

  5. FOR XML PATH 转换问题

    以下我带大家了解关于 FOR XML PATH 首先我们看下所熟悉的表数据 之后转换 <骨牌编号>1</骨牌编号> <骨牌颜色>橙</骨牌颜色> < ...

  6. 常用JS验证和函数

    下面是我常用一些JS验证和函数,有一些验证我直接写到了对象的属性里面了,可以直接通过对象.方法来调用 //浮点数除法运算 function fdiv(a, b, n) { if (n == undef ...

  7. SDL实现限制帧速

    很多人都在SDL_PollEvent和SDL_WaitEvent之间纠结.前者会带来更好的帧数表现,但是CPU占用极大,可以直接吃掉一个核心.后者则基本不占用CPU,但是帧数会受到影响.有没有办法使两 ...

  8. js简单日期获取( 菜鸟入门基础)

    关于js日期的获取要用到最基本的Date()方法获取当日的日期 var d =new Date();  //定义日期对象 var y=d.getFullYear();   //获取年 var m=d. ...

  9. java三大特性性:封装、继承和多态

    一.封装 封装是指隐藏对象的属性及实现细节,对外仅提供接口可见.封装实现了信息隐藏,利于软件复用.其优点是达到了模块化的标准,从而提高了代码的复用程度.在某种程度上,封装也大大改善了软件开发的可维护性 ...

  10. 用crontab、crond在嵌入式系统中添加定时任务

    在嵌入式系统中,定时任务通过crond和cronttab两个系统命令来联合执行. 其中crond是定时任务的守护进程,系统开始时是没有开启的.crontab主要作用是管理用户的crontab file ...