一、单独测试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. 图解JVM在内存中申请对象及垃圾回收流程

    http://longdick.iteye.com/blog/468368 先看一下JVM的内存模型: 从大的方面来讲,JVM的内存模型分为两大块: 永久区内存( Permanent space )和 ...

  2. Conversion to Dalvik format failed:Unable toexecute dex: method ID not in [0, 0xffff]: 65536

    关于方法数超限,Google官方给出的方案是这样的:https://developer.android.com/intl/zh-cn/tools/building/multidex.html 我也写过 ...

  3. c语言学习之基础知识点介绍(十二):结构体的介绍

    一.结构体的介绍 /* 语法: struct 结构体名{ 成员列表; }; 切记切记有分号! 说明:成员列表就是指你要保存哪些类型的数据. 注意:上面的语法只是定义一个新的类型,而这个类型叫做结构体类 ...

  4. C++实现RTMP协议发送H.264编码及AAC编码的音视频

    http://www.cnblogs.com/haibindev/archive/2011/12/29/2305712.html C++实现RTMP协议发送H.264编码及AAC编码的音视频 RTMP ...

  5. Java——类比较器

    1.Product类 public class Product { private int pid; private String name; private double price; public ...

  6. 时间处理总结(三)javascript与WCF

    1.WCF提交时间时,若需接受DateTime需转换为"\/Date(928120800000+0800)\/"这种格式 var DateToJson = function (js ...

  7. Jquery VailDate初探

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. iOS 计算两个日期之间的天数问题

    //获取当前时间若干年.月.日之后的时间 + (NSDate *)dateWithFromDate:(NSDate *)date years:(NSInteger)years months:(NSIn ...

  9. Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB

    Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB ...

  10. 基于SSM框架的简易的分页功能——包含maven项目的搭建

    新人第一次发帖,有什么不对的地方请多多指教~~ 分页这个功能经常会被使用到,我之前学习的时候找了很多资源,可都看不懂(笨死算了),最后还是在朋友帮助下做出了这个分页.我现在把我所能想到的知识 做了一个 ...