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. FullCalendar Timeline View 使用

    FullCalendar  Timeline View(v4) The Scheduler add-on provides a new view called “timeline view” with ...

  2. C++程序设计入门 之常量学习

    常量: 常量的定义格式:const datatype CONSTANTNAME = VALUE 常量的命名规范:符号常量(包括枚举值)必须全部大写并用下划线分隔单词 例如:MAX_ITERATIONS ...

  3. Python数值运算与赋值的快捷方式

    一种比较常见的操作是对一个变量进行一项数学运算并将运算得出的结果返回给这个变量,因此对于这类运算通常有如下的快捷表达方式: a = 2a = a * 3 同样也可写作: a = 2a *= 3 要注意 ...

  4. java四舍五入

    package com.clzhang.sample; import java.math.BigDecimal; import java.math.RoundingMode; import java. ...

  5. Spring3升级到Spring4时, 运行时出现找不到MappingJacksonHttpMessageConverter的情况

    [org.springframework.web.context.ContextLoader]Context initialization failed org.springframework.bea ...

  6. jzoj5341 捕老鼠

    Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕老鼠. 猫虽然擅长捕老鼠,但是老鼠们太健美了,身手敏捷,于是猫想 ...

  7. 通过IDEA解决spring配置文件

    来自:https://blog.csdn.net/yanghanxiu/article/details/79366263 (其实尼可以使用springboot 这样就不用配置一大堆东西了喵!) 每次创 ...

  8. Java并发工具类(一):等待多线程完成的CountDownLatch

    作用 CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行 简介 CountDownLatch是在java1.5被引入的,存在于java.uti ...

  9. How to get PrivateKey, PublicKey, Cert ID:

    0. Prepare cert.pfx and its password, verify_sign_acp.cer 1. Get Private Key $ openssl pkcs12 -in ce ...

  10. Python之时间模块、random模块、json与pickle模块

    一.时间模块 1.常用时间模块 import time # 时间分为三种格式 #1.时间戳---------------------以秒计算 # start= time.time() # time.s ...