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. 【CSS-进阶之元素:focus伪类模拟点击事件】

    先放上我们最终实现的效果 注:这里建议插入codepen(临时使用图片代替) 我们想要实现当点击某个元素时,显示一个tip浮动框. html: <div class="wrapper& ...

  2. js replace 全局替换

    js 的replace 默认替换只替换第一个匹配的字符,如果字符串有超过两个以上的对应字符就无法进行替换,这时候就要进行一点操作,进行全部替换. <script language="j ...

  3. CTF-Bugku-分析-信息提取

    CTF-Bugku-分析-信息提取 最近刷题的时候看到了这道比较有趣的题.而且网上也没找到wp,所以分享一下我的思路. 信息提取: 题目链接:http://ctf.bugku.com/challeng ...

  4. scala (3) Function 和 Method

    scala 定义函数的关键字是 val 定义函数的通用格式是  val  函数名 = (参数列表)=> {函数体} object FunctionDemo { //通用的定义格式 val f1 ...

  5. 由Handle转换为控件

    Control c = Control.FromHandle(this.textBox1.Handle); TextBox f = c as TextBox;

  6. 11-[CSS]-标准文档流,display,浮动,清除浮动,overflow

    1.标准文档流 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  7. GBDT+LR算法解析及Python实现

    1. GBDT + LR 是什么 本质上GBDT+LR是一种具有stacking思想的二分类器模型,所以可以用来解决二分类问题.这个方法出自于Facebook 2014年的论文 Practical L ...

  8. Macaca环境搭建全教程

    首先想要会Macaca,还得先会用github,不然你得死……因为各种例子都在git上,官网也一样,蛋疼的很…… #基础环境 1.JDK:jdk1.8-配置变量 2.Android SDK:sdk   ...

  9. idou老师教你学Istio:如何用 Istio 实现速率限制

    使用 Istio 可以很方便地实现速率限制.本文介绍了速率限制的使用场景,使用 memquota\redisquota adapter 实现速率限制的方法,通过配置 rule 实现有条件的速率限制,以 ...

  10. 设置JFrame背景图片

    这里我就放上改写的代码吧,不做多的解释,推荐一个好的博文 https://blog.csdn.net/jdsjlzx/article/details/16831815 public void ini_ ...