zoukankan      html  css  js  c++  java
  • Struts2整合Spring

      Struts2框架通过一种“可插拔式”的插件,为实现整合Spring框架提供了一种很简单的方式。Struts2整合Spring的关键就在与让Strut2的Action访问Spring容器中的业务逻辑组件。

    插件包(struts2-spring-plugin-x-x-x.jar)(作用)

    1、整合步骤:

    (1)为Web应用配置Struts2框架的开发环境

    (2)将Spring插件包struts2-spring-plugin-x-x-x.jar和spring.jar复制到WEB-INF/lib目录下

    (3)将commons-logging.jar也复制到lib目录下

    (4)在struts.properties文件中设置struts.objectFactory属性的值为spring,如下:

      struts.objectFactory=spring

         或者 在struts.xml文件中配置如下代码:

    <constant name="struts.objectFactory" value="spring"></constant>

    (5)在web.xml文件中配置Spring监听器,代码如下:

    spring listener
        <listener>
        <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
        </listener>
        <context-param>
        <param-name>contextConfigLocation </param-name>
        <param-value>/WEB-INF/classes/ApplicationContext.xml </param-value>
        </context-param>

    (6)在Web应用中配置Spring的核心配置文件applicationContext.xml

    ...

    2、整合示例

    用户登录

    (1)数据库设计 user表 (字段:userId,userName,password)

    (2)连接数据库类DataBaseConn.java

    (3)实体类User.java

    (4)DAO类 DataManage.java

    (5)登录界面login.jsp,登录成功界面loginSuccess.jsp

    (6)Action类 Login.java

    (7)struts.xml配置文件

    (8)applicationContext.xml配置文件

    (9)运行示例

  • 相关阅读:
    2015上阅读计划
    《梦断代码》读书笔记 第2篇
    四则运算3
    求数组中最大子数组的和(一维)
    四则运算2—单元测试
    四则运算2
    《梦断代码》读书笔记 第1篇
    四组运算2(思路)
    四则运算1
    读书笔记
  • 原文地址:https://www.cnblogs.com/zouteng/p/3061183.html
Copyright © 2011-2022 走看看