OA学习笔记-005-Spring2.5与struts2.1整合
一、单独测试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整合的更多相关文章
- OA学习笔记-001-项目介绍
基本知识 框架工具 解决方案(经典应用) 项目 12天 ========================================== OA项目, 12天 BBS 一.什么是OA? 辅助管理.提 ...
- [struts2学习笔记] 第五节 编写struts2的action代码
本文地址:http://blog.csdn.net/sushengmiyan/article/details/40479299 官方文档: http://struts.apache.org/relea ...
- 【Struts2学习笔记(12)】Struts2国际化
(1)准备资源文件,资源文件的命名格式例如以下: baseName_language_country.properties baseName_language.properties baseName. ...
- OA学习笔记-010-Struts部分源码分析、Intercepter、ModelDriver、OGNL、EL
一.分析 二. 1.OGNL 在访问action前,要经过各种intercepter,其中ParameterFilterInterceptor会把各咱参数放到ValueStack里,从而使OGNL可以 ...
- OA学习笔记-009-岗位管理的CRUD
一.分析 Action->Service->Dao CRUD有功能已经抽取到BaseDaoImpl中实现,所以RoleDaoImpl没有CRUD的代码,直接从BaseDaoImpl中继承 ...
- OA学习笔记-008-岗位管理Action层实现
一.分析 1,设计实体/表 设计实体 --> JavaBean --> hbm.xml --> 建表 2,分析有几个功能,对应几个请求. 3,实现功能: 1,写Action类,写Ac ...
- OA学习笔记-006-SPRING2.5与hibernate3.5整合
一.为什么要整合 1,管理SessionFactory实例(只需要一个) 2,声明式事务管理 spirng的作用 IOC 管理对象.. AOP 事务管理.. 二.整合步骤 1.整合sessionFac ...
- OA学习笔记-004-Spring2.5配置
一.jar包 (1)spring.jar (2)Aop包 aspectjrt.jaraspectjweaver.jar (3)动态代理 cglib-nodep-2.1_3.jar (4)日志 comm ...
- OA学习笔记-003-Hibernate3.6配置
一.jar包:核心包, 必须包, jpa, c3p0, jdbc antlr-2.7.6.jarc3p0-0.9.1.jarcommons-collections-3.1.jardom4j-1.6.1 ...
随机推荐
- Find Minimum in Rotated Sorted Array问题的困惑
今天做了两题,第二题没解出来,发现太麻烦了,放弃了……明天脑子清楚的时候再做. 第一题就是标题中的这个问题.在一个旋转排序数组中找出最小的值. 针对该问题出了两道不同要求的题目,分别是不考虑重复元素的 ...
- 浅谈Javase内存流程图
最近接触OOP面向对象,学习了OOP.this.super.package.extends还有override,整体来说如果不清楚内存的流程的话,对这些知识会很混淆,在老师的帮助下,花了一张图,能清楚 ...
- ASP.NET 预编译
ASP.NET 预编译概述 https://msdn.microsoft.com/zh-cn/library/bb398860%28v=VS.90%29.aspx 如何:预编译 ASP.NET 网站以 ...
- u盘的超级用法
转自360 U盘是大家最常用的移动存储设备,不过它的即插即用特性在给我们带来方便同时,也带来了极大的安全隐患.一款没有加密功能的U盘,在借给他人使用或不慎丢失时,其中所保存的资料将很容 ...
- WKWebView详解
WKWebView是在Apple的WWDC 2014随iOS 8和OS X 10.10出来的,是为了解决UIWebView加载速度慢.占用内存大的问题.使用UIWebView加载网页的时候,我们会发现 ...
- 不同浏览器下css 透明度的写法
filter:alpha(opacity=90); /* IE transparent */ -moz-opacity:0.9; /* Moz + FF transparent */ opacity: ...
- CSS3中的transform
CSS3 转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. transform 在2D里主要是4个方法.除了rotate 其他都是接受x y值 translate skew rotate sca ...
- java I/O技术
一.流的分类 Java的流类大部分都是由InputStream.OutputStream.Reader和Writer这四个抽象类派生出来的 (1)按数据流向 输入流(InputStream类和Read ...
- 'DEVENV' is not recognized as an internal or external command,
使用命令行 DEVENV 编译c# 工程, C:\MyProject>DEVENV "MyProject.sln" /build Release /useenv'DEVENV ...
- [翻译][MVC 5 + EF 6] 2:基础的增删改查(CRUD)
原文:Implementing Basic CRUD Functionality with the Entity Framework in ASP.NET MVC Application 1.修改Vi ...