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. HBase基础概念

    定义 非关系型分布式列式数据库,支持大数据量查询(百万,上亿行) 概要 数据存储:HDFS 数据计算:MapReduce/Spark 服务协调:Zookeeper 特征 列式存储(列只有一种类型byt ...

  2. 20145234黄斐《Java程序设计》实验三—敏捷开发与xp实践

    1在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Code菜单,找出一项让自己感觉最好用的功能.提交截图,加上自己学号水印. public cla ...

  3. 【转载】D3DXMatrixLookAtLH视图变换函数详解

    原文:D3DXMatrixLookAtLH视图变换函数详解 /*D3DXMatrixLookAtLH函数返回的是世界->视图变换矩阵. 视图坐标系和局部坐标系是一样的,都是世界坐标系转换为指定的 ...

  4. socket客户端和服务器端

    服务器端: #!/usr/bin/env python #-*- coding:utf-8 -*- import socket sk=socket.socket() sk.bind(('127.0.0 ...

  5. form提交方式Get与Post详解

    form作为Html的一个元素,它就是为了客户端提交数据而产生的,它有两个很重要的属性action和method,action属性指明了处理提交的数据的应用程序的URL,而method有两个值:POS ...

  6. js.ajax优缺点,工作流程

    1.ajax的优点 Ajax的给我们带来的好处大家基本上都深有体会,在这里我只简单的讲几点: 1.最大的一点是页面无刷新,在页面内与服务器通信,给用户的体验非常好.  2.使用异步方式与服务器通信,不 ...

  7. 域名配置https

    阿里可以一年的免费申请https证书 (1)域名->管理->免费开启SSL证书 (2)申请完.等待审核后就可以下载证书压缩包,包括key和pem两个文件 (3)在服务器的nginx目录下创 ...

  8. Django中settings设计模式(单例模式)

    配置文件: 需求:配置文件,默认配置和手动配置分开,参考django的配置文件方案,默认配置文件放在项目容器内部,只让用户做常用配置. /bin/settings.py(手动配置) PLUGIN_IT ...

  9. [Codeforces-911B] - Two Cakes

    B. Two Cakestime limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutpu ...

  10. GsonFormat插件主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高。

    GsonFormat插件主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高. 插件地址:https://plugins.jetbr ...