-----------------------siwuxie095

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

整合 Struts2 框架和 Spring 框架

 
 

 
 

1、导入相关
jar 包(共 27 个)

 
 

(1)导入
Struts2 的基本 jar 包(13 个)

 
 

 
 

 
 

其中:

 
 


Struts2 和 Hibernate 中,都有 javassist,会产生冲突,

选择高版本,删除低版本即可

 
 

 
 

 
 

(2)导入
Spring 的核心 jar 包和日志相关的 jar 包(6 个)

 
 

 
 

 
 

Commons Logging
下载链接:

 
 

http://commons.apache.org/proper/commons-logging/download_logging.cgi

 
 

 
 

LOG4J 下载链接:

 
 

https://www.apache.org/dist/logging/log4j/

 
 

 
 

 
 

(3)导入
Spring 的 AOP 开发的 jar 包(4 个)

 
 

 
 

 
 

AOP Alliance
下载链接:

 
 

http://mvnrepository.com/artifact/aopalliance/aopalliance

 
 

 
 

AspectJ Weaver
下载链接:

 
 

http://mvnrepository.com/artifact/org.aspectj/aspectjweaver

 
 

 
 

 
 

(4)导入
Spring 的
JDBC 开发的 jar 包(2 个)

 
 

 
 

 
 

 
 

(5)导入
Spring 整合 Web 项目的 jar 包(1 个)

 
 

 
 

 
 

 
 

(6)导入
Struts2 整合 Spring 的 jar 包(1 个)

 
 

 
 

 
 

 
 

 
 

2、测试

 
 

(1)编写一个
Action 类

 
 

UserAction.java:

 
 

package com.siwuxie095.action;

 
 

import com.opensymphony.xwork2.ActionSupport;

 
 

public class UserAction extends ActionSupport {

 
 

@Override

public String execute() throws Exception {

System.out.println("----- UserAction -----");

return
"none";

}

 

}

 
 

 
 

 
 

(2)在
Spring 核心配置文件中进行配置

 
 

applicationContext.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<beans
xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd">

 

 

<!-- 配置 Action 对象 -->

<bean
id="userAction"
class="com.siwuxie095.action.UserAction"
scope="prototype"></bean>

 

 
 

</beans>

 
 

 
 

 
 

(3)在
Struts2 核心配置文件中进行配置

 
 

struts.xml:

 
 

<?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="demo"
extends="struts-default"
namespace="/">

 

<!--

此时,class 属性对应 Spring 核心配置文件中 Bean 的 id

 

如果还写 Action 类的全限定名,Action 对象就会创建两次

-->

<action
name="user"
class="userAction"></action>

 

</package>

 
 

</struts>

 
 

 
 

 
 

(4)在部署描述文件中进行配置

 
 

web.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

 

 

<filter>

<!-- 配置 Struts2 的核心过滤器 -->

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

 

 

<!-- 配置 Spring 的监听器 ContextLoaderListener -->

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

 

 

</web-app>

 
 

 
 

 
 

(5)访问路径

 
 

http://localhost:8080/工程名/user.action

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

【made by siwuxie095】

整合Struts2框架和Spring框架的更多相关文章

  1. 整合SpringMVC框架和Spring框架

    -------------------------siwuxie095                                 整合 SpringMVC 框架和 Spring 框架       ...

  2. Eclipse/JavaWeb (三)三大框架之Spring框架 持续更新中...

    (一)发展历史 现在我们有三个层了,可是每层之间的调用是怎样的呢?比如显示层的struts需要调用一个业务类,就需要new一个业务类出来,然后使用:业务层需要调用持久层的类,也需要new一个持久层类出 ...

  3. 什么是Spring框架? Spring框架有哪些主要的模块?

    Spring框架是一个为java应用程序的开发提供了综合,广泛的基础性支持的java平台.Spring帮助开发者解决了开发中基础性的问题,使得开发人员可以专注于应用程序的开发.Spring框架本身亦是 ...

  4. Java - Struts框架教程 Hibernate框架教程 Spring框架入门教程(新版) sping mvc spring boot spring cloud Mybatis

    https://www.zhihu.com/question/21142149 http://how2j.cn/k/hibernate/hibernate-tutorial/31.html?tid=6 ...

  5. Java框架:spring框架整合hibernate框架的xml配置(使用注解的方式)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. Java框架之spring框架的优点,为什么要学习spring框架

    为什么要学习Spring的框架a: 方便解耦,简化开发    Spring就是一个大工厂,可以将所有对象创建和依赖关系维护,交给Spring管理 b:AOP编程的支持      Spring提供面向切 ...

  7. Spring框架学习(5)spring整合struts2

    内容源自:spring整合struts2 一.spring框架对struts等表现层框架的整合原理 : 使用spring的ioc容器管理struts中用于处理请求的Action 将Action配置成i ...

  8. SSH框架之Spring+Struts2+Hibernate整合篇

    回顾 -Hibernate框架 ORM: 对象关系映射.把数据库表和JavaBean通过映射的配置文件映射起来, 操作JavaBean对象,通过映射的配置文件生成SQL语句,自动执行.操作数据库. 1 ...

  9. 【Spring】Spring框架之Struts2和Spring的优点

    Java Web开发使用Structs2和Spring框架的好处 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术 ...

随机推荐

  1. [转]预编译 ASP.NET 网站

    转自:如何:预编译 ASP.NET 网站 Visual Studio 2005   预编译 ASP.NET 网站可缩短用户的初始响应时间,因为页在第一次被请求时无需编译.这对于经常更新的大型网站尤其有 ...

  2. 协同过滤CF算法之入门

    数据规整 首先将评分数据从 ratings.dat 中读出到一个 DataFrame 里: >>> import pandas as pd In [2]: import pandas ...

  3. centos-linux热拔插scsi硬盘

    自己配置虚拟机,需要添加一块虚拟硬盘存放数据.虚拟机在更新软件,不想停机.学习了下热拔插硬盘的知识点 1. 在虚拟机中创建虚拟磁盘并添加. 2. 查看目前的磁盘信息cat /proc/scsi/scs ...

  4. Server Tomcat v8.0 Server at localhost failed to start.的解决方法

    1.可能是web.xml中的filter-mapping中url-pattern没加/* 2.可能是servlet和servlet-mapping中的servlet-name不匹配

  5. [UE4]蒙太奇动画运行时不播放,预览是好的

    动画实例里面没有添加“DefaultSlot”就会出现这样的问题

  6. osx 安装redis

    brew install redis 想关文章 http://www.tuicool.com/articles/nM73Enr http://www.iteye.com/topic/1124400

  7. Python 实现双向链表(图解)

    原文:https://blog.csdn.net/qq490691606/article/details/49948263 git 路径 https://github.com/wangpanjun/d ...

  8. 测试运行kafka的时候缺少包的错误

    把kafka安装好了,在开启Kafka producer生产者,消费者的时候报这个错误 解决方法: 下载slf4j-1.7.6.ziphttp://www.slf4j.org/dist/slf4j-1 ...

  9. 3.2_k-近邻算法案例分析

        k-近邻算法案例分析 本案例使用最著名的”鸢尾“数据集,该数据集曾经被Fisher用在经典论文中,目前作为教科书般的数据样本预存在Scikit-learn的工具包中. 读入Iris数据集细节资 ...

  10. python气象分析

    数据分析实例 -- 气象数据 一.实验介绍 本实验将对意大利北部沿海地区的气象数据进行分析与可视化.我们在实验过程中先会运用 Python 中matplotlib库的对数据进行图表化处理,然后调用 s ...