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. 图片 和 base64 互转

    图片转base64 NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]]; UIImage *img = ...

  2. Git 最新版本2.20.1 安装及配置

    我们先去官网下载地址,去下载. https://git-scm.com/downloads 1. 2. 3. 双击 Git-2.20.1-64-bit.exe 安装 4. 5. 6. 7. 8. 9. ...

  3. 洛谷 P1762 偶数

    洛谷 P1762 偶数 题目描述 给定一个正整数n,请输出杨辉三角形前n行的偶数个数对1000003取模后的结果. 输入输出格式 输入格式: 一个数 输出格式: 结果 输入输出样例 输入样例#1:   ...

  4. Caffe on Windows (Visual Studio 2015+CUDA8.0+cuDNNv5)

    Title : Caffe (Visual Studio15+CUDA8+cuDNN5+python3.5) Author : SURFZJY Logo : True [TITLE] Requirem ...

  5. 洛咕 P2494 [SDOI2011]保密

    出题人没素质啊,强行拼题还把题面写得又臭又长. 简单题面就是有一张图,每条边有两个权值\(t,s\),有无限支军队,一支军队可以打一个点,代价是从n到这个点的路径的\(\frac{\sum t}{\s ...

  6. [BZOJ4028][HAOI2015]公约数数列[分块+分析暴力]

    题意 题目链接 分析 首先明确 \(xor\) 运算和 \(\rm gcd\) 没有联系! 注意到一个数字取 \(\rm gcd\) 且保证每次取 \(\rm gcd\) 值都会变小的话,最多取 \( ...

  7. jquery.validata1.11怎么支持metadata

    使用metadata方式这个需要使用jquery.metadata.js插件才可工作,通过在表单项中定义特殊的属性来指定验证规则 但是最新的jquery.validate 1.11没有内置metada ...

  8. Package设计1:选择数据类型、暂存数据和并发

    SSIS 设计系列: Package设计1:选择数据类型.暂存数据和并发 Package设计2:增量更新 Package 设计3:数据源的提取和使用暂存 一,数据类型的选择 对于SSIS的数据类型,容 ...

  9. 用 Python 带你看《我不是药神》

    我们都是小人物,我们都得了同一种病,我们都穷.——<我不是药神> 我不是程序员 我就是想求求你们,别动不动就拿篇10W+的文章来吓唬人好吗?说点有用的东西好吗?我们需要精神粮食不需要腐蚀精 ...

  10. 推荐11个实用Python库

    1.delorea 非常酷的日期/时间库 from delorean import Delorean EST = "US/Eastern"d = Delorean(timezone ...