Spring如何在web应用里面用

  1. 需要额外加入的jar包

    Spring-web-4.0.0

    Spring-webmvc-4.0.0

  2. Spring的配置文件,没什么不同

 

需要在web.xml下配置,使用myeclipse2014可自动生成

 

<!-- 启动ioc容器的servletcontextLin -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

 

<!-- 配置spring文件的位置 -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

 

配置好bean后

<body>

<%

//1.从application域对象中得到IOC容器的实例

ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(application);

 

//2.从IOC容器中得到bean

Person p=ctx.getBean(Person.class);

 

//3.使用bean

p.hello();

 

 

%>

 

 

如何整合struts2

目的:使ioc容器来管理struts2的Action

 

在spring的ioc容器中配置struts2的Action

注意:在IOC容器中配置struts2的Action时,配置scope属性,其值必须为prototype

<bean
id="personService"
class="com.test.spring_web.service.PersonService"></bean>

    

    <bean
id="personAction"
class="com.test.spring_web.action.PersonAction"

        scope="prototype">

        <property
name="personService"
ref="personService"></property>

    </bean>

 

配置struct2 的配置文件;action节点的class属性需要指向IOC容器中该bean的

<action
name="person-save"
class="personAction">

        <result>/success.jsp</result>

    </action>

 

注意需要加入文件

 

Spring笔记⑥--整合struts2的更多相关文章

  1. Spring 框架整合Struts2 框架和 Hibernate 框架

    1. Spring 框架整合 Struts2 框架 // [第一种整合方式(不推荐)](http://www.cnblogs.com/linkworld/p/7718274.html) // 从 Se ...

  2. Spring 学习笔记 整合 Struts2

           Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spri ...

  3. Spring框架整合Struts2

    1,用Spring架构,及Struts2-spring-plugin插件 导入Spring的dist全部所需的jar包 Struts2的spring插件 struts2-spring-plugin.X ...

  4. Spring框架整合Struts2框架的传统方法

    1. 导入CRM项目的UI页面,找到添加客户的页面,修改form表单,访问Action * 将menu.jsp中133行的新增客户的跳转地址改为:href="${pageContext.re ...

  5. Spring笔记⑤--整合hibernate代码测试

    String整合hibernate代码测试 在上节生成的表中插入数据:   注意:使用myeclipse2014生成的整合项目可能存在问题需要我们自己导入.   第一步 我们写dao接口 packag ...

  6. spring整合struts2

    1. Spring 如何在 WEB 应用中使用 ? 1). 需要额外加入的 jar 包: spring-web-4.0.0.RELEASE.jarspring-webmvc-4.0.0.RELEASE ...

  7. Spring 整合 Struts2

    1. Spring 如何在 WEB 应用中使用 ? 1). 需要额外加入的 jar 包: spring-web-4.0.0.RELEASE.jar spring-webmvc-4.0.0.RELEAS ...

  8. struts2 spring mybatis 整合(test)

    这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...

  9. Struts2的使用以及Spring整合Struts2

    一.如何单独使用Struts2 (1)引入struts2的jar包 commons-fileupload-1.2.1.jar freemarker-2.3.15.jar ognl-2.7.3.jar ...

随机推荐

  1. SharePoint document 右键菜单和【...】菜单不一致的解决办法

    [问题]在sharepoint 2016环境中,当用户只有read权限,访问文档库,会发现文档的右键菜单和[…]菜单的内如是不一致的,而更高权限用户都是一致的. [分析]这个跟微软询问过,是个bug, ...

  2. #leetcode刷题之路49-字母异位词分组

    给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串.示例:输入: ["eat", "tea", "tan" ...

  3. InnoDB数据页结构

    前言 ​ 关于数据库我们知道是通过内存对磁盘进行操作的,也知道数据会落实到磁盘上,但是数据在磁盘上的存储结构可能大家还不是很清楚. ​ MySQL服务器上负责对表中的数据的读取和写入的工作的部分是存储 ...

  4. Ubuntu安装后配置

    配置源将所有源配置为华科(mirrors.hust.edu.cn)或者中科大源(mirrors.ustc.edu.cn)使用vi编辑,使用命令 :%s/ubuntu源地址.com/mirrors.hu ...

  5. 批量分离SQL数据库语句

    --sp_helpdb--查看可用数据库 declare @name sysname, @sql nvarchar(4000) DECLARE roy CURSOR FOR --排除不分离的数据库名就 ...

  6. tomcat软连接的使用

    软连接说白了就是一个映射.可以映射文件,也可以映射目录.linux和windows都可以做软连接,加入现在把文件A.txt做软连接到B.txt: linux命令如下: ln -s A.txt B.tx ...

  7. Cannot find an exact (case-sensitive) match for 'crtbp.m

    http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=277326&page=1&extra=#pid3296048

  8. Hbase操作table常见方法示例

    首先上我的输出类: /** * 功能:电池历史数据数据结构 * Created by liuhuichao on 2016/12/5. */ public class ResBatteryDataHi ...

  9. 2_C语言中的数据类型 (一)2.1.常量和字符串常量

    2.1 常量就是在程序中不可变化的量,常量在定义的时候必须给一个初值. 1.1.1          #define 定义一个宏常量 1.1.2          const 定义一个const常量 ...

  10. 六种流行的语言大餐---C、C++、python、Java、php、C#你更喜欢哪一个呢?

    引言 鉴于五一期间超大的人流量,LZ思来想去,最终还是选择蜗居在自己的出租屋.无聊之际,当然不能忘了做点什么事情,于是LZ就研究了一下几种语言的皮毛,在这里献丑一翻,希望各位猿友莫要见笑. 不过说来也 ...