一、单独测试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. 基于u盘安装centos6.0

    本人在dell笔记本上尝试安装centos6.0,与win7形成双系统,安装过程如下: 1.使用ultraliso制作u盘启动盘,启动盘以centos6.0的映像文件为源头制作: 2.制作完成后,删除 ...

  2. js数组&&字符串&&定时器2

    一.系统时间对象Date 方法 描述 Date() 返回当日的日期和时间. getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31). getDay() 从 Date 对象返回一周 ...

  3. css所有选择器的详解

    ----------------------------------------css 选择器---------------------------------------- 1,组合选择器: 1)e ...

  4. postgresql 行转列,列转行后加入到一个整体数据

    这里行转列的基本思想就是使用max,因为其他列下面都是NULL,所以可以Max最后就只能得到有值的这行 普通的查询: SELECT icd , case when (ROW_NUMBER() OVER ...

  5. Redis 集群常见问题

    Redis集群相关问题 1:远程连接问题 远程连接保护模式下,需要做一些配置.

  6. 将vs2012的项目转化成VS2010

    vs2012生成的项目,如何在只装有VS2010的电脑上打开, 步骤: 1.打开一个记事本,将你的Vs2012生成的项目解决方案文件(.sln文件)文件拖到记事本中 2.修改前两行  Microsof ...

  7. Android开发之Menu组件

    菜单Menu大致分为三种类型:选项菜单(OptionsMenu),上下文菜单(ContextMenu),子菜单(SubMenu). 1.选项菜单 在一个Activity界面中点击手机Menu键,在屏幕 ...

  8. phaser源码解析(三) Phaser.Utils类下isPlainObject方法

    /** * #这是一个对jQuery.isPlainObject(obj)稍加修改的方法. 一个 普通对象 obj.toString() => "[object Object]&quo ...

  9. JSP EL表达式详细介绍

    一.JSP EL语言定义 E L(Expression Language)  目的:为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 ...

  10. C/C++中memset函数

    本文学习参考http://baike.baidu.com/link?url=ZmSyY8ciB_nJt9KM-W2fiEFJrC2mugFsLqRdY2b4pLe8rD_jRXyN7_pj0GBBD2 ...