zoukankan      html  css  js  c++  java
  • Spring笔记⑥--整合struts2

    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>

     

    注意需要加入文件

     

  • 相关阅读:
    CAST和CONVERT
    #pragma 预处理指令详解
    Android系统移植主要事项
    Java动态绑定机制的内幕
    Java接口和抽象类用法总结
    Android工程的编译过程
    点击按钮,并且实现增加一个按钮的效果 (附效果图)
    iOS-设置导航栏"返回"按钮 (附效果图)
    常用代码整理(重要)
    NSTimer 的暂停与恢复运行。
  • 原文地址:https://www.cnblogs.com/chengzhipcx/p/4770496.html
Copyright © 2011-2022 走看看