整合Struts2框架和Spring框架
来源:互联网 发布:linux 虚拟机不能上网 编辑:程序博客网 时间:2024/05/22 15:52
-----------------------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 UserActionextends ActionSupport {
@Override
public String execute()throws Exception {
System.out.println("----- UserAction -----");
return"none";
}
}
(2)在Spring 核心配置文件中进行配置
applicationContext.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="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对象 -->
<beanid="userAction"class="com.siwuxie095.action.UserAction"scope="prototype"></bean>
</beans>
(3)在Struts2 核心配置文件中进行配置
struts.xml:
<?xmlversion="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>
<packagename="demo"extends="struts-default"namespace="/">
<!--
此时,class属性对应 Spring核心配置文件中 Bean的 id
如果还写 Action类的全限定名,Action对象就会创建两次
-->
<actionname="user"class="userAction"></action>
</package>
</struts>
(4)在部署描述文件中进行配置
web.xml:
<?xmlversion="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/javaeehttp://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框架
- struts2+spring整合框架
- SSH框架整合(Spring整合Struts2,和Spring整合Hibernate)
- spring和mybatis ,hibernate, struts2框架整合
- struts2和spring框架的整合
- SSH框架整合之Struts2和Spring整合
- struts2+hibernate+spring框架整合
- mybatis+spring+struts2框架整合
- mybatis+spring+struts2框架整合
- struts2+spring+ibatis框架整合
- struts2+mybatis+spring框架整合
- mybatis+spring+struts2框架整合
- struts2+spring+ibatis框架整合
- struts2+spring+ibatis框架整合
- mybatis+spring+struts2框架整合
- Struts2+spring+Mybatis框架整合
- Struts2+Hibernate+spring框架整合
- hibernate+struts2+spring框架整合
- 一个DOM元素绑定多个事件时,先执行冒泡还是捕获
- 使用Spring自定义注解实现任务路由
- 剑指offer(17)—树的子结构
- mysql获取当天,昨天,本周,本月,上周,上月的起始时间
- My-Redis
- 整合Struts2框架和Spring框架
- JavaScript进阶:深入理解原型与原型链
- c#--WinForm-查询结果的排序
- tomcat性能调优和性能监控(visualvm)
- JavaScript学习(三) 变量 作用域和内存
- shell脚本
- c++容器存放不同结构的数据
- Android 自定义ScrollView可监控滑动方向、滑动到底部
- Android实现仿QQ的图片上传方式