前言

本博文主要讲解Spring怎么与Struts2框架整合...

Struts2和Spring的整合关键点

  • action对象交给Spring来创建

搭建环境

进入jar包

引入jar文件:

  • 1)引入struts .jar相关文件
  • 2)spring-core 相关jar文件
  • 3)spring-web 支持jar包
    • spring-web-3.2.5.RELEASE.jar 【Spring源码】
    • struts2-spring-plugin-2.3.4.1.jar 【Struts源码】

写配置文件

  • struts.xml 【struts路径与action映射配置】
  • bean.xml 【spring ioc容器配置】
  • web.xml
    • 【核心过滤器: 引入struts功能】
    • 【初始化spring的ioc容器】查看Spring的API

web.xml文件

web.xml文件

除了要配置Struts2的分配器,还要加载Spring的配置文件


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 2. spring 配置 -->
<context-param>
<param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/bean*</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </web-app>

编写Spring配置文件


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> </beans>


编写Struts2配置文件


<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<package name="aaa" extends="struts-default"> <action name="bbb" class="userAction">
<result name="success" >/2.jsp</result>
</action> </package> </struts>

最后

如果文章有错的地方欢迎指正,大家互相交流。习惯在微信看技术文章,想要获取更多的Java资源的同学,可以关注微信公众号:Java3y

Struts2与Spring整合的更多相关文章

  1. 二十六:Struts2 和 spring整合

    二十六:Struts2 和 spring整合 将项目名称为day29_02_struts2Spring下的scr目录下的Struts.xml文件拷贝到新项目的scr目录下 在新项目的WebRoot-- ...

  2. 第一次做的struts2与spring整合

    参考:http://www.cnblogs.com/S-E-P/archive/2012/01/18/2325253.html 这篇文章说的关键就是“除了导入Struts2和Spring的核心库之外, ...

  3. Struts2学习笔记——Struts2与Spring整合

      Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...

  4. Struts2+Hibernate+Spring 整合示例

    转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...

  5. Struts2+Hibernate+Spring 整合示例[转]

    原文 http://blog.csdn.net/tkd03072010/article/details/7468769 Spring整合Struts2.Hibernate原理概述: 从用户角度来看,用 ...

  6. Spring第四篇【Intellij idea环境下、Struts2和Spring整合】

    前言 Spring的第二和第三篇已经讲解了Spring的基本要点了[也就是Core模块]-本博文主要讲解Spring怎么与Struts2框架整合- Struts2和Spring的整合关键点: acti ...

  7. struts2与spring整合时需要注意的点

    首先我们需要明白spring整合struts2中的什么东西,spring中的核心就是IOC和AOP,IOC是对象的容器,AOP是处理动态代理的;比如spring与hibernate整合时就要用到aop ...

  8. struts2 与spring整合

    要把struts2的action交给spring管理,这样spring才干帮struts2注入须要的的bean(一開始action是由struts初始化,所以想注入spring里面的bean是注入不了 ...

  9. SSH Struts2+hiberante+Spring整合

    使用SSH框架编写学生信息: 一.新建Java工程: (1)建立好Java各层级之间的结构:业务处理层dao,数据模型层domain,页面请求处理层(Struts2 MVC层)action,servi ...

随机推荐

  1. jdk12+tomcat9 配置

    jdk12 没有了jre的配置   直接配置path就可以了 tomcat常规配置,只是启动的时候麻烦一点   需要重新写入jdk jre jvm 到server.bat文件 参考文章: https: ...

  2. 执行grunt命令报错 Cannot find module 'coffee-script'

    Failed to list grunt tasks in yudian-frontend-salesplatform\Gruntfile.js: process finished with exit ...

  3. 使用自建Git服务器管理私有项目 Centos 7.3 + Git 2.11.0 + gitosis (实测 笔记)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso GIT服务器IP:192.168.1 ...

  4. Katalon Studio之请求响应中文乱码解决方法

    最近在用Katalon做接口测试过程中发现请求响应消息中返回的中文均为乱码,这是因为我们使用的系统环境在初始安装时选择的中文简体,导致windows系统默认编码格式为GBK,但是KS的编码格式是UTF ...

  5. Redmine 安装、搭建

    参考两个博客: 1.https://blog.csdn.net/g19881118/article/details/59476045 2.https://www.cnblogs.com/chendal ...

  6. XLua----热更新

    一.xLua 环境配置 1).Xlua中  Plugin  Xlua复制到 需要热更新的工程中---->Assets子目录 2).开启宏HOTFIX_ENABLE File---->bui ...

  7. DB2 数据库的安装配置及监控

    一.DB2简介 IBM公司研制的一种关系型数据库系统.DB2主要应用于大型应用系统,具有较好的可伸缩性,可支持从大型机到单用户环境,应用于OS/2.Windows等平台下. DB2提供了高层次的数据利 ...

  8. 电子科技大学第九届ACM趣味程序设计竞赛(热身赛)题解

    比赛地址:http://acm.uestc.edu.cn/#/contest/show/191 A题 小羽涂色 题意: 在x轴的正半轴上,问你是否存在一段区间[L,R]其中包含r个奇数和g个偶数. 分 ...

  9. FCC(ES6写法) Inventory Update

    依照一个存着新进货物的二维数组,更新存着现有库存(在 arr1 中)的二维数组. 如果货物已存在则更新数量 . 如果没有对应货物则把其加入到数组中,更新最新的数量. 返回当前的库存数组,且按货物名称的 ...

  10. mysql查看编码格式以及修改编码格式

    1.进入mysql,输入show variables like 'character%';查看当前字符集编码情况,显示如下: 其中,character_set_client为客户端编码方式: char ...