java struts spring_Struts2与Spring整合

前言

本博文主要讲解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源码】

1ee2ba42a99bd11cf62240dad1064656.png

写配置文件

struts.xml 【struts路径与action映射配置】

bean.xml 【spring ioc容器配置】

web.xml

【核心过滤器: 引入struts功能】

【初始化spring的ioc容器】查看Spring的API

web.xml文件

web.xml文件

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

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">

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

contextConfigLocation

/WEB-INF/classes/bean*

org.springframework.web.context.ContextLoaderListener

ce390d30be08f3adc9a5e24bf6e38382.png

编写Spring配置文件

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">

bba7509542aea2933b851b06a456711b.png

7f82d7b823d0d09f03de88b729c449b1.png

编写Struts2配置文件

/p>

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

/2.jsp

7f777753c453999cc135e571e02b2c1a.png

最后

93deb9a2e09fec620339f554dc464e49.png

4b7bf5b7024b17b9fdb8a8910ee98f49.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值